Skip to content

Commit

Permalink
Merge pull request #247 from hyeeyoung/dev-mod-passowrd-api
Browse files Browse the repository at this point in the history
[mod] 비밀번호 api 수정
  • Loading branch information
hyejungg authored Mar 8, 2023
2 parents 4264043 + 3d413c0 commit 0d07023
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
3 changes: 2 additions & 1 deletion src/controllers/userController.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,10 @@ module.exports = {
},
updateUserPassword: async function (req, res, next) {
try {
if (!req.body.email || !req.body.password) {
if (!req.body.newPassword) {
throw new BadRequest(ErrorMessage.BadRequestMeg);
}

await User.updatePassword(req).then(() => {
res.status(StatusCode.OK).json({
success: true,
Expand Down
10 changes: 4 additions & 6 deletions src/models/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -208,13 +208,11 @@ module.exports = {
},
updatePassword: async function (req) {
const userId = Number(req.decoded);
const email = req.body.email;
const password = req.body.password;
const hashPassword = bcrypt.hashSync(password, 10);
const newPassword = req.body.newPassword;
const hashPassword = bcrypt.hashSync(newPassword, 10);

const sqlUpdate =
'UPDATE users SET password = ? WHERE email = ? AND user_id = ?';
const params = [hashPassword, email, userId];
const sqlUpdate = 'UPDATE users SET password = ? WHERE user_id = ?';
const params = [hashPassword, userId];

const [rows] = await db.queryWithTransaction(sqlUpdate, params);

Expand Down

0 comments on commit 0d07023

Please sign in to comment.