salix/services/client/common/models/Address.js

14 lines
470 B
JavaScript
Raw Normal View History

2017-01-18 09:42:53 +00:00
module.exports = function(Address) {
Address.validate('default',isEnabled,{message: 'No se puede poner predeterminado un consignatario desactivado'});
function isEnabled(err) {
if (!this.enabled && this.default) err();
}
Address.observe('before save', function (ctx, next) {
if (ctx.data.enabled && ctx.data.default) {
ctx.Model.update({client: ctx.data.client}, {default: false});
}
next();
});
};