I need to encrypt the password only if some criteria is fullfilled.
beforeUpdate: function (value, cb) {
User.findOne(value.id)
.exec(function (err, originalUser) {
if (err || !originalUser) {
return cb();
}
//encrypt the password only if the password is not previously encrypted
if (value.password != originalUser.password) {
//encrypt the Pwd
} else {
cb();
}
});
} The problem is that, the value object only contains the update params, how can I get the whole user object in the value object?
After the update of async, this method does not work anymore.
You can not get the whole object inside beforeUpdate. You can try this to get the id.
var id= this.update.arguments[0]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With