231801_test_to_master #1519

Merged
alexm merged 490 commits from 231801_test_to_master into master 2023-05-12 06:29:59 +00:00
2 changed files with 14 additions and 31 deletions
Showing only changes of commit c0deb745d6 - Show all commits

View File

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

View File

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