Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

conditional beforeUpdate in sails

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?

like image 464
Luja Shrestha Avatar asked Nov 25 '25 20:11

Luja Shrestha


1 Answers

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]

like image 60
hasan3050 Avatar answered Nov 28 '25 16:11

hasan3050