SailsJS provides default blueprint actions, such as find, update, create, etc.
I need to override some of them to suit particular business purposes. However, I would lik
You should look at lifecycle callbacks in sailsjs. So for example, you can use beforeUpdate or beforeCreate lifecycle callback to do more in the model:
var bcrypt = require('bcrypt');
module.exports = {
attributes: {
username: {
type: 'string',
required: true
},
password: {
type: 'string',
minLength: 6,
required: true,
columnName: 'encrypted_password'
}
},
// Lifecycle Callbacks
beforeCreate: function (values, cb) {
// Encrypt password
bcrypt.hash(values.password, 10, function(err, hash) {
if(err) return cb(err);
values.password = hash;
//calling cb() with an argument returns an error. Useful for canceling the entire operation if some criteria fails.
cb();
});
}
};