Skip to content

Commit

Permalink
refactor: Add UpdateUserFCMTokenDTO for updating user's FCM token
Browse files Browse the repository at this point in the history
  • Loading branch information
suk-6 committed Jul 13, 2024
1 parent 138595f commit f98062b
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 6 deletions.
10 changes: 10 additions & 0 deletions src/modules/user/dto/update-user-fcm.dto.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { Prisma } from '@prisma/client';

import { ApiProperty } from '@nestjs/swagger';

export class UpdateUserFCMTokenDTO implements Prisma.UserUpdateInput {
@ApiProperty({
required: true,
})
FCMToken: string;
}
37 changes: 31 additions & 6 deletions src/modules/user/user.controller.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { Prisma, User } from '@prisma/client';
import { User } from '@prisma/client';

import { Body, Controller, Delete, Get, Param, Patch, Put, Req, UseGuards } from '@nestjs/common';
import { AuthGuard } from '@nestjs/passport';
import { ApiBearerAuth, ApiBody, ApiOkResponse, ApiOperation, ApiTags, ApiUnauthorizedResponse } from '@nestjs/swagger';

import { CurrentUser, ResponseDTO } from 'src/common';

import { UpdateUserFCMTokenDTO } from './dto/update-user-fcm.dto';
import { UpdateUserDTO } from './dto/update-user.dto';
import { UploadProfileImageDTO } from './dto/upload-profile-image.dto';
import { UserResponseDTO } from './dto/user.dto';
Expand All @@ -26,6 +27,27 @@ export class UserController {
return await this.userService.findUserById(req.user.id);
}

@Patch('/')
@UseGuards(AuthGuard('access'))
@ApiBearerAuth()
@ApiBody({
type: UpdateUserDTO,
})
@ApiOperation({ summary: 'Update user information' })
@ApiOkResponse({
description: 'User information updated',
type: ResponseDTO<null>,
})
@ApiUnauthorizedResponse({ description: 'Unauthorized' })
async updateUser(@CurrentUser() user: User, @Body() data: UpdateUserDTO): Promise<ResponseDTO<null>> {
try {
await this.userService.updateUserById(user.id, data);
return { status: 'success', data: null };
} catch (error) {
return { status: 'error', data: null };
}
}

@Get('/:userId')
@UseGuards(AuthGuard('access'))
@ApiBearerAuth()
Expand All @@ -36,19 +58,22 @@ export class UserController {
return await this.userService.findUserById(userId);
}

@Patch('/')
@Put('/fcm')
@UseGuards(AuthGuard('access'))
@ApiBearerAuth()
@ApiBody({
type: UpdateUserDTO,
type: UpdateUserFCMTokenDTO,
})
@ApiOperation({ summary: 'Update user information' })
@ApiOperation({ summary: 'Update user FCM token' })
@ApiOkResponse({
description: 'User information updated',
description: 'User FCM token updated',
type: ResponseDTO<null>,
})
@ApiUnauthorizedResponse({ description: 'Unauthorized' })
async updateUser(@CurrentUser() user: User, @Body() data: Prisma.UserUpdateInput): Promise<ResponseDTO<null>> {
async updateUserFCMToken(
@CurrentUser() user: User,
@Body() data: UpdateUserFCMTokenDTO,
): Promise<ResponseDTO<null>> {
try {
await this.userService.updateUserById(user.id, data);
return { status: 'success', data: null };
Expand Down

0 comments on commit f98062b

Please sign in to comment.