diff --git a/controllers/notificationController.js b/controllers/notificationController.js index ea4ba49..4d4b5cb 100644 --- a/controllers/notificationController.js +++ b/controllers/notificationController.js @@ -98,6 +98,7 @@ const createNotification = async (req, res) => { message, notificationType, url, + notificationId: notification.id, }); res.status(200).json({ status: { success: true, code: 200, message: notification }, diff --git a/controllers/userController.js b/controllers/userController.js index 1b1086e..0dbac4b 100644 --- a/controllers/userController.js +++ b/controllers/userController.js @@ -236,6 +236,18 @@ const passwordChange = async (req, res) => { } }; +const profileImageDelete = async (req, res) => { + const { id: userId } = req.user; + try { + await userService.profileImageDelete(userId); + res.status(200).json({ status: { success: true } }); + } catch (error) { + res.status(500).json({ + status: { success: false, code: 500, message: error.message }, + }); + } +}; + export default { signup, deleteUser, @@ -251,4 +263,5 @@ export default { checkEmail, resetPassword, passwordChange, + profileImageDelete, }; diff --git a/repositorys/userRepository.js b/repositorys/userRepository.js index 99a163a..09a9a52 100644 --- a/repositorys/userRepository.js +++ b/repositorys/userRepository.js @@ -356,6 +356,15 @@ const passwordChange = async (userId, newPassword, confirmPassword) => { }); return; }; + +const profileImageDelete = async (userId) => { + await prisma.user.update({ + where: { id: userId }, + data: { profile_image: null }, + }); + return; +}; + export default { createUser, deleteUser, @@ -370,4 +379,5 @@ export default { checkEmail, resetPassword, passwordChange, + profileImageDelete, }; diff --git a/router/userRouter.js b/router/userRouter.js index 85eb0ef..a9555bd 100644 --- a/router/userRouter.js +++ b/router/userRouter.js @@ -1083,4 +1083,54 @@ router.patch( userController.passwordChange ); +/** + * @swagger + * /api/v1/user/profile-image-delete: + * delete: + * tags: + * - User + * summary: 프로필 이미지 삭제 + * description: 사용자의 프로필 이미지를 삭제합니다. + * security: + * - bearerAuth: [] + * responses: + * '200': + * description: 프로필 이미지 삭제 성공 + * content: + * application/json: + * schema: + * type: object + * properties: + * status: + * type: object + * properties: + * success: + * type: boolean + * example: true + * '500': + * description: 서버 에러 + * content: + * application/json: + * schema: + * type: object + * properties: + * status: + * type: object + * properties: + * success: + * type: boolean + * example: false + * code: + * type: integer + * example: 500 + * message: + * type: string + * example: "프로필 이미지 삭제 중 오류가 발생했습니다." + */ +router.delete( + '/profile-image-delete', + jwtToken.accessVerifyToken, + userController.profileImageDelete +); + export default router; diff --git a/services/userService.js b/services/userService.js index 9c6e5e5..e6acb1a 100644 --- a/services/userService.js +++ b/services/userService.js @@ -115,6 +115,11 @@ const passwordChange = async (userId, newPassword, confirmPassword) => { return user; }; +const profileImageDelete = async (userId) => { + const user = await userRepository.profileImageDelete(userId); + return user; +}; + export default { createUser, deleteUser, @@ -129,4 +134,5 @@ export default { checkEmail, resetPassword, passwordChange, + profileImageDelete, };