14 lines
470 B
JavaScript
14 lines
470 B
JavaScript
|
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();
|
||
|
});
|
||
|
};
|