Skip to content

Commit

Permalink
[feat] 아이디 찾기 API #2
Browse files Browse the repository at this point in the history
  • Loading branch information
root committed Aug 4, 2023
1 parent 589c71c commit 536d849
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 4 deletions.
21 changes: 21 additions & 0 deletions src/app/User/userController.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,27 @@ exports.login = async function (req, res) {
return res.send(signInResponse);
};

/**
* API No. 4
* API Name : 아이디 찾기 API
* [GET] /users/auth/id/{userEmail}
*/
exports.findUserId = async function (req, res) {

/**
* Path Variable: userEmail
*/
const userEmail = req.params.userEmail;

if (!userEmail) return res.send(errResponse(baseResponse.USER_USEREMAIL_EMPTY));

const findUserIdResponse = await userService.findUserId(userEmail);

console.log(findUserIdResponse);

return res.send(findUserIdResponse);
};


/**
* API No. 5
Expand Down
7 changes: 4 additions & 3 deletions src/app/User/userDao.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,12 @@ async function selectUser(connection) {
// 이메일로 회원 조회
async function selectUserEmail(connection, email) {
const selectUserEmailQuery = `
SELECT email, nickname
FROM UserInfo
WHERE email = ?;
SELECT EMAIL, UserId
FROM User_Personal
WHERE EMAIL = ?;
`;
const [emailRows] = await connection.query(selectUserEmailQuery, email);

return emailRows;
}

Expand Down
2 changes: 2 additions & 0 deletions src/app/User/userProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ exports.retrieveUser = async function (userId) {
exports.emailCheck = async function (email) {
const connection = await pool.getConnection(async (conn) => conn);
const emailCheckResult = await userDao.selectUserEmail(connection, email);

console.log(`추가된 회원 : ${emailCheckResult}`);
connection.release();

return emailCheckResult;
Expand Down
3 changes: 3 additions & 0 deletions src/app/User/userRoute.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ module.exports = function(app){
// 3. 특정 유저 조회 API
app.get('/app/users/:userId', user.getUserById);

// 4. 아이디 찾기 API
app.get('/users/auth/id/:userEmail', user.findUserId);


// TODO: After 로그인 인증 방법 (JWT)
// 로그인 하기 API (JWT 생성)
Expand Down
21 changes: 20 additions & 1 deletion src/app/User/userService.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,4 +109,23 @@ exports.editUser = async function (id, nickname) {
logger.error(`App - editUser Service error\n: ${err.message}`);
return errResponse(baseResponse.DB_ERROR);
}
}
}

exports.findUserId = async function (email) {
try {
// 해당 이메일에 관한 유저가 있는지 확인
const emailRows = await userProvider.emailCheck(email);

if (emailRows.length == 0)
return errResponse(baseResponse.USER_USEREMAIL_NOT_EXIST);

let userId=emailRows[0].UserId;

return response(baseResponse.SUCCESS, {'userEmail': email, 'userId': userId});


} catch (err) {
logger.error(`App - createUser Service error\n: ${err.message}`);
return errResponse(baseResponse.DB_ERROR);
}
};

0 comments on commit 536d849

Please sign in to comment.