Skip to content

Commit

Permalink
refactor: Update UserController to update user's FCM token
Browse files Browse the repository at this point in the history
  • Loading branch information
suk-6 committed Jul 19, 2024
1 parent 7d48759 commit 70b5433
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/modules/user/user.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ export class UserController {
@Body() data: UpdateUserFCMTokenDTO,
): Promise<ResponseDTO<null>> {
try {
await this.userService.updateUserById(user.id, data);
await this.userService.updateUserFCMTokenById(user.id, data.FCMToken);
return { status: 'success', data: null };
} catch (error) {
return { status: 'error', data: null };
Expand Down
10 changes: 10 additions & 0 deletions src/modules/user/user.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,16 @@ export class UserService {
return data;
}

async updateUserFCMTokenById(id: string, FCMToken: string) {
const user = await this.prisma.user.findUnique({ where: { id } });
if (!user) throw new HttpException('User not found', HttpStatus.NOT_FOUND);

await this.prisma.user.update({
where: { id },
data: { FCMToken },
});
}

/**
* Update user profile image by id
* @param id User id
Expand Down

0 comments on commit 70b5433

Please sign in to comment.