39 lines
1.2 KiB
TypeScript
39 lines
1.2 KiB
TypeScript
import { Resolver, Query, Mutation, Args, ID } from '@nestjs/graphql';
|
|
import { UsersService } from './users.service';
|
|
import { User } from './entities/user.entity';
|
|
import { UseGuards } from '@nestjs/common';
|
|
import { GqlAuthGuard } from '../auth/guards/gql-auth.guard';
|
|
import { CurrentUser } from '../auth/decorators/current-user.decorator';
|
|
|
|
@Resolver(() => User)
|
|
export class UsersResolver {
|
|
constructor(private readonly usersService: UsersService) {}
|
|
|
|
@Query(() => [User], { name: 'users' })
|
|
@UseGuards(GqlAuthGuard)
|
|
findAll() {
|
|
return this.usersService.findAll();
|
|
}
|
|
|
|
@Query(() => User, { name: 'user' })
|
|
@UseGuards(GqlAuthGuard)
|
|
findOne(@Args('id', { type: () => ID }) id: string) {
|
|
return this.usersService.findOne(id);
|
|
}
|
|
|
|
@Query(() => User, { name: 'me' })
|
|
@UseGuards(GqlAuthGuard)
|
|
getMe(@CurrentUser() user: User) {
|
|
return this.usersService.findOne(user.id);
|
|
}
|
|
|
|
@Mutation(() => User)
|
|
@UseGuards(GqlAuthGuard)
|
|
updateUser(
|
|
@CurrentUser() user: User,
|
|
@Args('bio', { nullable: true }) bio?: string,
|
|
@Args('avatar', { nullable: true }) avatar?: string,
|
|
) {
|
|
return this.usersService.update(user.id, { bio, avatar });
|
|
}
|
|
} |