Skip to content
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

Merged
merged 5 commits into from
Jan 15, 2022
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 63 additions & 0 deletions src/controller/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,68 @@ import returnCode from "../library/returnCode";
// services
import authService from "../service/auth";

/**
* @이메일 유효성 검사
* @route GET /auth/email
* @access public
* @err 1. 필요한 값이 없을 때
* 2. 이메일 형식이 올바르지 않을 때
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

에러? 🧐 에러? 🧐 에러? 🧐 에러? 🧐

* 3. 이메일이 이미 존재할 때
Copy link
Contributor

Choose a reason for hiding this comment

The 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);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

오 resData도 형식 지정 .. 저도 일케 해보겠슴다 .. 🤨🤨🤨

Copy link
Member

Choose a reason for hiding this comment

The 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
Expand Down Expand Up @@ -147,6 +209,7 @@ const postLoginController = async (req: Request, res: Response) => {
}
};
const authController = {
getEmailController,
postSignupController,
postLoginController,
};
Expand Down
1 change: 1 addition & 0 deletions src/router/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const router = express.Router();
// Controller
import authController from "../controller/auth";

router.get("/email", authController.getEmailController);
router.post("/login", authController.postLoginController);
router.post("/signup", authController.postSignupController);

Expand Down
33 changes: 33 additions & 0 deletions src/service/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Copy link
Contributor

@seohyun-106 seohyun-106 Jan 15, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

아 맞다 이거 .. 근데 요 상수값은 controller에서는 안쓰는데 클린코드를 위해 사용하는건가여? 🤨🤨🤨

};

/**
* @회원가입
* @route POST /auth/signup
Expand Down Expand Up @@ -127,6 +159,7 @@ const postLoginService = async (email: string, password: string) => {
};

const authService = {
getEmailService,
postSignupService,
postLoginService,
};
Expand Down