refs #5540 arreglo en supplier

This commit is contained in:
Carlos Satorres 2023-04-28 14:03:21 +02:00
parent 38142c121d
commit c0deb745d6
2 changed files with 14 additions and 31 deletions

View File

@ -24,18 +24,18 @@ module.exports = Self => {
message: 'TIN must be unique'
});
// async function fiInvalid(err, done) {
// const filter = {
// fields: ['code'],
// where: {id: this.countryFk}
// };
// const countryCode = this.fi.toUpperCase().substring(0, 2);
// const country = await Self.app.models.Country.findOne(filter);
// const code = country ? country.code : null;
// if (this.isVies && countryCode == code)
// err();
// done();
// }
async function fiInvalid(err, done) {
const filter = {
fields: ['code'],
where: {id: this.countryFk}
};
const countryCode = this.fi.toUpperCase().substring(0, 2);
const country = await Self.app.models.Country.findOne(filter);
const code = country ? country.code : null;
if (this.isVies && countryCode == code)
err();
done();
}
Self.validatesFormatOf('email', {
message: 'Invalid email',

View File

@ -32,10 +32,6 @@ module.exports = Self => {
message: 'TIN must be unique'
});
Self.validateAsync('nif', nifInvalid, {
message: 'Invalid NIF for VIES'
});
Self.validateAsync('nif', tinIsValid, {
message: 'Invalid TIN'
});
@ -71,22 +67,9 @@ module.exports = Self => {
};
const country = await Self.app.models.Country.findOne(filter);
const code = country ? country.code.toLowerCase() : null;
const countryCode = this.nif.toLowerCase().substring(0, 2);
if (!this.nif || !validateTin(this.nif, code))
err();
done();
}
Self.validateAsync('nif', nifInvalid);
async function nifInvalid(err, done) {
const filter = {
fields: ['code'],
where: {id: this.countryFk}
};
const countryCode = this.nif.toUpperCase().substring(0, 2);
const country = await Self.app.models.Country.findOne(filter);
const code = country ? country.code : null;
if (this.isVies && countryCode == code)
if (!this.nif || !validateTin(this.nif, code) || (this.isVies && countryCode == code))
err();
done();
}