我猜我的代码运行良好,但它没有更新我数据库中的数据。请帮帮我。
这是我的控制器:
module.exports.editPassword = (params) => {
const user = User.findById(params.userId)
console.log(user)
// if(bcrypt.compareSync(params.password, user.password)) {
const updates = {
firstName: params.firstName,
lastName: params.lastName,
email: params.email,
password: bcrypt.hashSync(params.password, 10)
}
return User.findByIdAndUpdate(params.userId, updates).then((updated, err) => {
return (err) ? false : true
})
}
这是我的路线:
router.put('/update', auth.verify, (req, res) => {
UserController.editPassword(req.body)
.then(resultFromUpdate =>
res.send(resultFromUpdate))
})