diff --git a/src/controller/userController.ts b/src/controller/userController.ts index 1003378..c79aedb 100644 --- a/src/controller/userController.ts +++ b/src/controller/userController.ts @@ -8,64 +8,79 @@ import { userTokenCheck } from "../constants/userTokenCheck"; //* 유저닉네임 중복 검사 const postDuplicateNickname = async (req: Request, res: Response) => { - const userId = req.body.userId; - const { nickname } = req.body; - - if (!nickname) { - return res.status(sc.BAD_REQUEST).send(fail(sc.BAD_REQUEST, rm.NULL_NICKNAME)); - } - - const refinedNickname = nickname.replace(/ /g,""); - - try { - - const data = await userService.postDuplicateNickname(+userId, refinedNickname); - if (!data) { - return res.status(sc.BAD_REQUEST).send(fail(sc.BAD_REQUEST, rm.FAIL_CHECK_NICKNAME)) - } - - return res.status(sc.OK).send(success(sc.OK, rm.SUCCESS_CHECK_NICKNAME, data)); - - } catch (error) { - const errorMessage = slackErrorMessage(req.method.toUpperCase(), req.originalUrl, error, req.statusCode); - - sendWebhookMessage(errorMessage); - - res.status(sc.INTERNAL_SERVER_ERROR) - .send(fail(sc.INTERNAL_SERVER_ERROR, rm.INTERNAL_SERVER_ERROR)); + const userId = req.body.userId; + const { nickname } = req.body; + + if (!nickname) { + return res + .status(sc.BAD_REQUEST) + .send(fail(sc.BAD_REQUEST, rm.NULL_NICKNAME)); + } + + const refinedNickname = nickname.replace(/ /g, ""); + + try { + const data = await userService.postDuplicateNickname( + +userId, + refinedNickname + ); + if (!data) { + return res + .status(sc.BAD_REQUEST) + .send(fail(sc.BAD_REQUEST, rm.FAIL_CHECK_NICKNAME)); } -} - -const getUserVersion = async (req: Request, res:Response) => { - const userId = req.body.userId; - if (!userId) { - return res.status(sc.BAD_REQUEST).send(fail(sc.BAD_REQUEST, rm.BAD_REQUEST)); - } - - try { - const data = await userService.getUserVersion(+userId); - - if(!data) { - return res.status(sc.BAD_REQUEST).send(fail(sc.BAD_REQUEST, rm.BAD_REQUEST)) - } - - return res.status(sc.OK).send(success(sc.OK, rm.GET_USER_VERSION_SUCCESS, data)); - - } catch (error) { - const errorMessage = slackErrorMessage(req.method.toUpperCase(), req.originalUrl, error, req.statusCode); - - sendWebhookMessage(errorMessage); - - res.status(sc.INTERNAL_SERVER_ERROR) - .send(fail(sc.INTERNAL_SERVER_ERROR, rm.INTERNAL_SERVER_ERROR)); + return res + .status(sc.OK) + .send(success(sc.OK, rm.SUCCESS_CHECK_NICKNAME, data)); + } catch (error) { + const errorMessage = slackErrorMessage( + req.method.toUpperCase(), + req.originalUrl, + error, + req.statusCode + ); + + sendWebhookMessage(errorMessage); + + res + .status(sc.INTERNAL_SERVER_ERROR) + .send(fail(sc.INTERNAL_SERVER_ERROR, rm.INTERNAL_SERVER_ERROR)); + } +}; + +const getUserVersion = async (req: Request, res: Response) => { + try { + const data = await userService.getUserVersion(); + + if (!data) { + return res + .status(sc.BAD_REQUEST) + .send(fail(sc.BAD_REQUEST, rm.BAD_REQUEST)); } -} + return res + .status(sc.OK) + .send(success(sc.OK, rm.GET_USER_VERSION_SUCCESS, data)); + } catch (error) { + const errorMessage = slackErrorMessage( + req.method.toUpperCase(), + req.originalUrl, + error, + req.statusCode + ); + + sendWebhookMessage(errorMessage); + + res + .status(sc.INTERNAL_SERVER_ERROR) + .send(fail(sc.INTERNAL_SERVER_ERROR, rm.INTERNAL_SERVER_ERROR)); + } +}; const userController = { - postDuplicateNickname, - getUserVersion -} + postDuplicateNickname, + getUserVersion, +}; -export default userController; \ No newline at end of file +export default userController; diff --git a/src/service/userService.ts b/src/service/userService.ts index 61b64bb..f935573 100644 --- a/src/service/userService.ts +++ b/src/service/userService.ts @@ -80,9 +80,7 @@ const getUserByRfToken = async (refreshToken: string) => { return user; }; -const getUserVersion = async ( - userId: number -): Promise => { +const getUserVersion = async (): Promise => { const versionData = await prisma.version.findUnique({ where: { id: 1,