diff --git a/src/controller/userController.ts b/src/controller/userController.ts index dd9f873..a154b17 100644 --- a/src/controller/userController.ts +++ b/src/controller/userController.ts @@ -17,6 +17,22 @@ const accessUserInfo = async (req: Request, res: Response, next: NextFunction) = } }; +const updateUserInfo = async (req: Request, res: Response, next: NextFunction) => { + const refreshToken = req.body.refreshToken; + const themeColor = req.body.themeColor; + + try { + const data = await userService.updateUserInfo(refreshToken, themeColor); + + return res + .status(statusCode.CREATED) + .send(success(statusCode.CREATED, message.UPDATE_USERINFO_SUCCESS, data)); + } catch (error) { + next(error); + } + }; + export default { - accessUserInfo + accessUserInfo, + updateUserInfo }; \ No newline at end of file diff --git a/src/module/constant/responseMessage.ts b/src/module/constant/responseMessage.ts index 9cbfea1..fa2d1d7 100644 --- a/src/module/constant/responseMessage.ts +++ b/src/module/constant/responseMessage.ts @@ -11,4 +11,5 @@ export default { MAKE_FEEDBACK_SUCCESS: "피드백 생성 성공", SAVE_EMOTION_SUCCESS: "감정 저장 성공", ACCESS_USERINFO_SUCCESS: "프로필 조회 성공", + UPDATE_USERINFO_SUCCESS: "프로필 수정 성공", }; \ No newline at end of file diff --git a/src/router/userRouter.ts b/src/router/userRouter.ts index 44c1084..c003703 100644 --- a/src/router/userRouter.ts +++ b/src/router/userRouter.ts @@ -14,4 +14,14 @@ router.get( userController.accessUserInfo, ); +router.patch( + '/', + [ + body('refreshToken').notEmpty(), + body('themeColor'), + ], + errorValidator, + userController.updateUserInfo, + ); + export default router; \ No newline at end of file diff --git a/src/service/userService.ts b/src/service/userService.ts index 69c717d..c26ac80 100644 --- a/src/service/userService.ts +++ b/src/service/userService.ts @@ -23,6 +23,27 @@ const accessUserInfo = async (refreshToken: string) => { } }; +const updateUserInfo = async (refreshToken: string, themeColor: string) => { + try { + const userInfo = await prisma.user.update({ + where: { + refreshToken: refreshToken, + }, + select: { + id: true, + userName: true, + pictureURL: true, + themeColor: themeColor, + refreshToken: true, + } + }); + return userInfo; + } catch(error) { + throw error; + } +}; + export default { accessUserInfo, + updateUserInfo, }; \ No newline at end of file