Skip to content

Commit

Permalink
Merge pull request #50 from TeamBookTez/feat/get-user-email-api
Browse files Browse the repository at this point in the history
Feat/get user email api
  • Loading branch information
geeneve authored Jan 15, 2022
2 parents 7e69b11 + 9dd9941 commit 8813235
Show file tree
Hide file tree
Showing 3 changed files with 87 additions and 0 deletions.
55 changes: 55 additions & 0 deletions src/controller/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,60 @@ import returnCode from "../library/returnCode";
// services
import authService from "../service/auth";

/**
* @이메일 유효성 검사
* @route GET /auth/email
* @access public
* @err 1. 필요한 값이 없을 때
*/
const getEmailController = async (req: Request, res: Response) => {
try {
const resData: number = await authService.getEmailService(req.body.email);

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,
{ isValid: false }
);
} else if (resData === constant.EMAIL_ALREADY_EXIST) {
response.dataResponse(
res,
returnCode.OK,
"이미 사용 중인 이메일입니다.",
true,
{ isValid: false }
);
} else {
response.dataResponse(
res,
returnCode.OK,
"사용할 수 있는 이메일입니다.",
true,
{ isValid: 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 +201,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
31 changes: 31 additions & 0 deletions src/service/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,36 @@ import isEmail from "validator/lib/isEmail";
// models
import { User } from "../models";

/**
* @이메일 유효성 검사
* @route GET /auth/email
* @access public
* @err 1. 필요한 값이 없을 때
*/
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;
};

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

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

0 comments on commit 8813235

Please sign in to comment.