Skip to content

Commit

Permalink
Feat(#501): 유저 fcm 기기 토큰 삭제
Browse files Browse the repository at this point in the history
  • Loading branch information
j-zzi committed May 10, 2024
1 parent 283582f commit f73d399
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/notification/controllers/notification.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,4 +106,15 @@ export class NotificationController {
registerDeviceTokenDto,
);
}

@ApiNotification.DeleteDeviceToken({ summary: 'fcm 디바이스 토큰 삭제' })
@UseGuards(AllowUserAndLecturerGuard)
@Delete('device-token')
async deleteDeviceToken(@GetAuthorizedUser() authorizedData: ValidateResult) {
const userId = authorizedData.lecturer
? authorizedData.lecturer.userId
: authorizedData.user.id;

return await this.notificationService.deleteUserDeviceToken(userId);
}
}
10 changes: 10 additions & 0 deletions src/notification/controllers/swagger/notification.swagger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,4 +90,14 @@ export const ApiNotification: ApiOperator<keyof NotificationController> = {
),
);
},
DeleteDeviceToken: function (
apiOperationOptions: Required<Pick<Partial<OperationObject>, 'summary'>> &
Partial<OperationObject>,
): PropertyDecorator {
return applyDecorators(
ApiOperation(apiOperationOptions),
ApiBearerAuth(),
StatusResponseDto.swaggerBuilder(HttpStatus.OK, 'deleteUserDeviceToken'),
);
},
};
4 changes: 4 additions & 0 deletions src/notification/repositories/notification.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,4 +105,8 @@ export class NotificationRepository {
where: { userId },
});
}

async deleteUserDeviceToken(userId: number): Promise<void> {
await this.prismaService.userDeviceToken.delete({ where: { userId } });
}
}
4 changes: 4 additions & 0 deletions src/notification/services/notification.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -317,4 +317,8 @@ export class NotificationService {
token: userDeviceToken.deviceToken,
};
}

async deleteUserDeviceToken(userId: number) {
return await this.notificationRepository.deleteUserDeviceToken(userId);
}
}

0 comments on commit f73d399

Please sign in to comment.