Skip to content

Commit

Permalink
Feat: DuplicateCheck #2
Browse files Browse the repository at this point in the history
  • Loading branch information
khl6235 committed Sep 26, 2021
1 parent 2536acf commit c58787b
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 6 deletions.
11 changes: 10 additions & 1 deletion vinyla/controllers/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,15 @@ module.exports = {
},

duplicateCheck: async(req, res) => {

const {nickname} = req.body;
if(!nickname){
return await res.status(statusCode.BAD_REQUEST).send(util.fail(statusCode.BAD_REQUEST, resMessage.NULL_VALUE));
}
const isDuplicate = await UserModel.duplicateCheck(nickname);
if(!isDuplicate){
return await res.status(statusCode.BAD_REQUEST).send(util.fail(statusCode.BAD_REQUEST, resMessage.ALREADY_NICKNAME));
}

return await res.status(statusCode.OK).send(util.success(statusCode.OK, resMessage.NO_DUPLICATE, {nickname: nickname}));
}
};
17 changes: 17 additions & 0 deletions vinyla/models/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,23 @@ const user = {
console.log('[SIGNUP] err: ' + err);
throw err;
}
},

duplicateCheck : async({nickname}) => {
try{
const sql = `SELECT COUNT(*) as cnt FROM user WHERE nickname = ?`;
const value = [nickname];
const rs = await pool.queryParam_Parse(sql, value);
if(rs[0].cnt == 0){
return true;
}
else{
return false;
}
} catch (err) {
console.log('[DUPLICATECHECK] err: ' + err);
throw err;
}
}
};

Expand Down
9 changes: 4 additions & 5 deletions vinyla/modules/responseMessage.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,13 @@ module.exports = {
NULL_VALUE: "ν•„μš”ν•œ 값이 μ—†μŠ΅λ‹ˆλ‹€",
OUT_OF_VALUE: "νŒŒλΌλ―Έν„° 값이 잘λͺ»λ˜μ—ˆμŠ΅λ‹ˆλ‹€",

// νšŒμ›κ°€μž…
// User
CREATE_USER: "νšŒμ› κ°€μž… 성곡",
DELETE_USER: "νšŒμ› νƒˆν‡΄ 성곡",
ALREADY_NAME: "이미 μ‚¬μš©μ€‘μΈ λ‹‰λ„€μž„μž…λ‹ˆλ‹€.",
ALREADY_EMAIL: "이미 μ‚¬μš©μ€‘μΈ μ΄λ©”μΌμž…λ‹ˆλ‹€.",
NO_DUPLICATE: "μ‚¬μš© κ°€λŠ₯ν•œ 이메일과 λ‹‰λ„€μž„μž…λ‹ˆλ‹€.",

ALREADY_NICKNAME: "μ‚¬μš© 쀑인 λ‹‰λ„€μž„μž…λ‹ˆλ‹€.",
NO_DUPLICATE: "μ‚¬μš© κ°€λŠ₯ν•œ λ‹‰λ„€μž„μž…λ‹ˆλ‹€.",

// 둜그인
LOGIN_SUCCESS: "둜그인 성곡",
LOGIN_FAIL: "둜그인 μ‹€νŒ¨",
NO_USER: "μ‘΄μž¬ν•˜μ§€ μ•ŠλŠ” νšŒμ›μž…λ‹ˆλ‹€."
Expand Down

0 comments on commit c58787b

Please sign in to comment.