Skip to content

Commit

Permalink
Merge pull request #29 from TEAM-ITERVIEW/#28
Browse files Browse the repository at this point in the history
[feat] 프로필 수정 API
  • Loading branch information
cha2y0ung authored Mar 28, 2024
2 parents 159ddbc + 1d45478 commit 20d436f
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 1 deletion.
18 changes: 17 additions & 1 deletion src/controller/userController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
};
1 change: 1 addition & 0 deletions src/module/constant/responseMessage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ export default {
MAKE_FEEDBACK_SUCCESS: "피드백 생성 성공",
SAVE_EMOTION_SUCCESS: "감정 저장 성공",
ACCESS_USERINFO_SUCCESS: "프로필 조회 성공",
UPDATE_USERINFO_SUCCESS: "프로필 수정 성공",
};
10 changes: 10 additions & 0 deletions src/router/userRouter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,14 @@ router.get(
userController.accessUserInfo,
);

router.patch(
'/',
[
body('refreshToken').notEmpty(),
body('themeColor'),
],
errorValidator,
userController.updateUserInfo,
);

export default router;
21 changes: 21 additions & 0 deletions src/service/userService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};

0 comments on commit 20d436f

Please sign in to comment.