Initial commit: Prism messenger with Expo + NestJS + GraphQL + PostgreSQL
This commit is contained in:
39
backend/src/modules/users/users.resolver.ts
Normal file
39
backend/src/modules/users/users.resolver.ts
Normal file
@ -0,0 +1,39 @@
|
||||
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 });
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user