Errores en validación solucionados
This commit is contained in:
parent
daaf73a143
commit
025bd4224e
|
@ -56,9 +56,6 @@ export const validators = {
|
|||
|
||||
if (!valid)
|
||||
throw new Error(`Invalid value`);
|
||||
},
|
||||
uniqueness: function() {
|
||||
// TODO: Implement me
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -93,14 +90,14 @@ export function validate(value, conf) {
|
|||
}
|
||||
|
||||
/**
|
||||
* Checks if value satisfies a not null validation.
|
||||
* Checks if value satisfies a blank or not null validation.
|
||||
*
|
||||
* @param {*} value The value
|
||||
* @param {Object} conf The validation configuration
|
||||
*/
|
||||
export function checkNull(value, conf) {
|
||||
if (value === '' && !conf.allowBlank) {
|
||||
if (conf.allowBlank === false && value === '')
|
||||
throw new Error(`Value can't be blank`);
|
||||
} else if (value == null && !conf.allowNull)
|
||||
else if (conf.allowNull === false && value == null)
|
||||
throw new Error(`Value can't be null`);
|
||||
}
|
||||
|
|
|
@ -41,8 +41,9 @@ module.exports = function(Client) {
|
|||
message: 'No se puede cambiar la forma de pago si no hay comercial asignado'
|
||||
});
|
||||
function hasSalesMan(err) {
|
||||
if(this.payMethod && !this.salesPerson) err();
|
||||
};
|
||||
if(this.payMethod && !this.salesPerson)
|
||||
err();
|
||||
}
|
||||
|
||||
Client.validateAsync('payMethodFk', hasIban, {
|
||||
message: 'El método de pago seleccionado requiere que se especifique el IBAN'
|
||||
|
@ -51,32 +52,27 @@ module.exports = function(Client) {
|
|||
let iban = this.iban;
|
||||
let PayMethod = Client.app.models.PayMethod;
|
||||
PayMethod.findById(this.payMethodFk, function (_, instance) {
|
||||
if (instance.ibanRequired && !iban)
|
||||
if (instance && instance.ibanRequired && !iban)
|
||||
err();
|
||||
done();
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
// Hooks
|
||||
|
||||
Client.observe('before save', function(ctx, next) {
|
||||
if (ctx.instance) {
|
||||
if (!ctx.instance.dueDay){
|
||||
if (!ctx.instance.dueDay)
|
||||
ctx.instance.dueDay = 5;
|
||||
}
|
||||
next();
|
||||
}
|
||||
else {
|
||||
Client.findById(ctx.where.id,
|
||||
function(err, item) {
|
||||
if (!err) {
|
||||
if (item.payMethod != ctx.data.payMethod && item.dueDay == ctx.data.dueDay) {
|
||||
} else {
|
||||
Client.findById(ctx.where.id, function(err, instance) {
|
||||
if (instance
|
||||
&& instance.payMethodFk != ctx.data.payMethodFk
|
||||
&& instance.dueDay == ctx.data.dueDay)
|
||||
ctx.data.dueDay = 5;
|
||||
}
|
||||
}
|
||||
next();
|
||||
}
|
||||
);
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
|
|
Loading…
Reference in New Issue