From d9192770a6a2938bc50684b81d41c3611c2bd419 Mon Sep 17 00:00:00 2001 From: seohyun-106 Date: Wed, 12 Jan 2022 12:36:50 +0900 Subject: [PATCH 1/5] fix: remove unnecessary variable declaration --- src/controller/auth.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/controller/auth.ts b/src/controller/auth.ts index 89fc302..f4afb7e 100644 --- a/src/controller/auth.ts +++ b/src/controller/auth.ts @@ -125,7 +125,6 @@ const postLoginController = async (req: Request, res: Response) => { "비밀번호가 일치하지 않습니다." ); } else { - const { nickname, token } = data; response.dataResponse( res, returnCode.OK, From 54b6d97309a733f816b744625737da4fc26def4c Mon Sep 17 00:00:00 2001 From: seohyun-106 Date: Wed, 12 Jan 2022 14:29:29 +0900 Subject: [PATCH 2/5] fix: replace data with resData --- src/controller/auth.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/controller/auth.ts b/src/controller/auth.ts index f4afb7e..422678a 100644 --- a/src/controller/auth.ts +++ b/src/controller/auth.ts @@ -101,23 +101,23 @@ const postSignupController = async (req: Request, res: Response) => { const postLoginController = async (req: Request, res: Response) => { try { const { email, password } = req.body; - const data = await authService.postLoginService(email, password); + const resData = await authService.postLoginService(email, password); - if (data === -1) { + if (resData === -1) { response.basicResponse( res, returnCode.BAD_REQUEST, false, "필요한 값이 없습니다." ); - } else if (data === -2) { + } else if (resData === -2) { response.basicResponse( res, returnCode.NOT_FOUND, false, "존재하지 않는 이메일입니다." ); - } else if (data === -3) { + } else if (resData === -3) { response.basicResponse( res, returnCode.BAD_REQUEST, @@ -130,7 +130,7 @@ const postLoginController = async (req: Request, res: Response) => { returnCode.OK, "장서현의 첫 api 소중히 다뤄주세요 💋", true, - data + resData ); } } catch (err) { From d2e8e618554f41b9e7f31705835fe2c48a7cf35b Mon Sep 17 00:00:00 2001 From: seohyun-106 Date: Wed, 12 Jan 2022 14:33:58 +0900 Subject: [PATCH 3/5] fix: apply constant to statusCode --- src/controller/auth.ts | 6 +++--- src/service/auth.ts | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/controller/auth.ts b/src/controller/auth.ts index 422678a..109bcc5 100644 --- a/src/controller/auth.ts +++ b/src/controller/auth.ts @@ -103,21 +103,21 @@ const postLoginController = async (req: Request, res: Response) => { const { email, password } = req.body; const resData = await authService.postLoginService(email, password); - if (resData === -1) { + if (resData === constant.NULL_VALUE) { response.basicResponse( res, returnCode.BAD_REQUEST, false, "필요한 값이 없습니다." ); - } else if (resData === -2) { + } else if (resData === -100) { response.basicResponse( res, returnCode.NOT_FOUND, false, "존재하지 않는 이메일입니다." ); - } else if (resData === -3) { + } else if (resData === -101) { response.basicResponse( res, returnCode.BAD_REQUEST, diff --git a/src/service/auth.ts b/src/service/auth.ts index e249a6d..ba5493b 100644 --- a/src/service/auth.ts +++ b/src/service/auth.ts @@ -100,19 +100,19 @@ const postSignupService = async ({ email, nickname, password }) => { const postLoginService = async (email: string, password: string) => { // 요청 바디 부족 if (!email || !password) { - return -1; + return constant.NULL_VALUE; } // 존재하지 않는 이메일 const user = await User.findOne({ where: { email: email } }); if (!user) { - return -2; + return -100; } // 비밀번호 일치 X const isMatch = await bcrypt.compare(password, user.password); if (!isMatch) { - return -3; + return -101; } // 성공 시 From c622dcbc004bf562970f74d9d62b547d6d3b6fc8 Mon Sep 17 00:00:00 2001 From: seohyun-106 Date: Wed, 12 Jan 2022 14:37:04 +0900 Subject: [PATCH 4/5] fix: combine Controller parameter to req.body --- src/controller/auth.ts | 3 +-- src/service/auth.ts | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/src/controller/auth.ts b/src/controller/auth.ts index 109bcc5..144f281 100644 --- a/src/controller/auth.ts +++ b/src/controller/auth.ts @@ -100,8 +100,7 @@ const postSignupController = async (req: Request, res: Response) => { const postLoginController = async (req: Request, res: Response) => { try { - const { email, password } = req.body; - const resData = await authService.postLoginService(email, password); + const resData = await authService.postLoginService(req.body); if (resData === constant.NULL_VALUE) { response.basicResponse( diff --git a/src/service/auth.ts b/src/service/auth.ts index ba5493b..594addd 100644 --- a/src/service/auth.ts +++ b/src/service/auth.ts @@ -97,7 +97,7 @@ const postSignupService = async ({ email, nickname, password }) => { * @access public */ -const postLoginService = async (email: string, password: string) => { +const postLoginService = async ({ email, password }) => { // 요청 바디 부족 if (!email || !password) { return constant.NULL_VALUE; From 0c07a75059a99c6515125c08d2f7cfe449091c7e Mon Sep 17 00:00:00 2001 From: seohyun-106 Date: Wed, 12 Jan 2022 14:43:32 +0900 Subject: [PATCH 5/5] fix: apply prettier --- src/controller/auth.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/controller/auth.ts b/src/controller/auth.ts index 144f281..60ce275 100644 --- a/src/controller/auth.ts +++ b/src/controller/auth.ts @@ -144,7 +144,7 @@ const postLoginController = async (req: Request, res: Response) => { } }; const authController = { - postSignupController, + postSignupController, postLoginController, };