-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feat/get user email api #50
Changes from 3 commits
37dfa35
f7fe793
df60ead
6993afd
9dd9941
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,6 +11,68 @@ import returnCode from "../library/returnCode"; | |
// services | ||
import authService from "../service/auth"; | ||
|
||
/** | ||
* @이메일 유효성 검사 | ||
* @route GET /auth/email | ||
* @access public | ||
* @err 1. 필요한 값이 없을 때 | ||
* 2. 이메일 형식이 올바르지 않을 때 | ||
* 3. 이메일이 이미 존재할 때 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 에러? 🧐 에러? 🧐 에러? 🧐 에러? 🧐 |
||
*/ | ||
const getEmailController = async (req: Request, res: Response) => { | ||
try { | ||
const resData: number = await authService.getEmailService(req.body.email); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 오 resData도 형식 지정 .. 저도 일케 해보겠슴다 .. 🤨🤨🤨 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 오호,, 꼼꼼보이 |
||
|
||
if (resData === constant.NULL_VALUE) { | ||
response.basicResponse( | ||
res, | ||
returnCode.BAD_REQUEST, | ||
false, | ||
"필요한 값이 없습니다." | ||
); | ||
} else if (resData === constant.WRONG_EMAIL_CONVENTION) { | ||
response.dataResponse( | ||
res, | ||
returnCode.OK, | ||
"올바른 형식이 아닙니다.", | ||
true, | ||
{ | ||
isUnique: false, | ||
} | ||
); | ||
} else if (resData === constant.EMAIL_ALREADY_EXIST) { | ||
response.dataResponse( | ||
res, | ||
returnCode.OK, | ||
"이미 사용 중인 이메일입니다.", | ||
true, | ||
{ | ||
isUnique: false, | ||
} | ||
); | ||
} else { | ||
response.dataResponse( | ||
res, | ||
returnCode.OK, | ||
"사용할 수 있는 이메일입니다.", | ||
true, | ||
{ | ||
isUnique: true, | ||
} | ||
); | ||
} | ||
} catch (err) { | ||
slack.slackWebhook(req, err.message); | ||
console.error(err.message); | ||
response.basicResponse( | ||
res, | ||
returnCode.INTERNAL_SERVER_ERROR, | ||
false, | ||
"서버 오류" | ||
); | ||
} | ||
}; | ||
|
||
/** | ||
* @회원가입 | ||
* @route POST /auth/signup | ||
|
@@ -147,6 +209,7 @@ const postLoginController = async (req: Request, res: Response) => { | |
} | ||
}; | ||
const authController = { | ||
getEmailController, | ||
postSignupController, | ||
postLoginController, | ||
}; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,6 +9,38 @@ import isEmail from "validator/lib/isEmail"; | |
// models | ||
import { User } from "../models"; | ||
|
||
/** | ||
* @이메일 유효성 검사 | ||
* @route GET /auth/email | ||
* @access public | ||
* @err 1. 필요한 값이 없을 때 | ||
* 2. 이메일 형식이 올바르지 않을 때 | ||
* 3. 이메일이 이미 존재할 때 | ||
*/ | ||
const getEmailService = async (email: string) => { | ||
// 필요한 값이 존재하지 않는 경우 | ||
if (!email) { | ||
return constant.NULL_VALUE; | ||
} | ||
|
||
// email 형식이 잘못되었을 때 | ||
if (!isEmail(email)) { | ||
return constant.WRONG_EMAIL_CONVENTION; | ||
} | ||
|
||
// email이 이미 존재할 때 | ||
const emailExist = await User.findAll({ | ||
where: { | ||
email, | ||
}, | ||
}); | ||
if (emailExist.length > 0) { | ||
return constant.EMAIL_ALREADY_EXIST; | ||
} | ||
|
||
return constant.SUCCESS; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 아 맞다 이거 .. 근데 요 상수값은 controller에서는 안쓰는데 클린코드를 위해 사용하는건가여? 🤨🤨🤨 |
||
}; | ||
|
||
/** | ||
* @회원가입 | ||
* @route POST /auth/signup | ||
|
@@ -127,6 +159,7 @@ const postLoginService = async (email: string, password: string) => { | |
}; | ||
|
||
const authService = { | ||
getEmailService, | ||
postSignupService, | ||
postLoginService, | ||
}; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
에러? 🧐 에러? 🧐 에러? 🧐 에러? 🧐