Update awards endpoint data and fix reset pass bug

This commit is contained in:
Mr Swift
2024-08-28 13:02:35 +03:30
parent b120ae1708
commit 588eec13e8
4 changed files with 47 additions and 7 deletions
+8 -2
View File
@@ -279,9 +279,15 @@ module.exports.update_user_password = [
const salt = await bcrypt.genSalt(10)
const hash = await bcrypt.hash(newPassword, salt)
const user = await User.findById(user_id)
if (!user) throw new Error(_faSr.not_found.user_id)
if (!user) {
res.status(404)
throw new Error(_faSr.not_found.user_id)
}
const passwordMatch = await bcrypt.compare(password, user.password)
if (!passwordMatch) throw new Error('err')
if (!passwordMatch) {
res.status(401)
throw new Error('err')
}
user.password = hash
await user.save()
return res.json({ message: _faSr.response.success_save })