refs #5540 validate
gitea/salix/pipeline/head Build queued... Details

This commit is contained in:
Carlos Satorres 2023-04-28 10:21:54 +02:00
parent b8f7f7bd69
commit cdbbec9d36
2 changed files with 20 additions and 8 deletions

View File

@ -1,12 +1,14 @@
module.exports = async function(fi) { const models = require('vn-loopback/server/server').models;
module.exports = async function(fi, isVies, countryFk) {
const filter = { const filter = {
fields: ['code'], fields: ['code'],
where: {id: this.countryFk} where: {id: countryFk}
}; };
const countryCode = this.fi.toUpperCase().substring(0, 2); const countryCode = fi.toUpperCase().substring(0, 2);
const country = await app.models.Country.findOne(filter); const country = await models.Country.findOne(filter);
const code = country ? country.code : null; const code = country ? country.code : null;
if (this.isVies && countryCode == code) if (isVies && countryCode == code)
err(); return false;
done(); return true;
}; };

View File

@ -24,7 +24,7 @@ module.exports = Self => {
message: 'TIN must be unique' message: 'TIN must be unique'
}); });
Self.validateAsync('fi', validateNIF(fi), { Self.validateAsync(validateNIF(this.fi, this.isVies, this.countryFk), {
message: 'Invalid TIN' message: 'Invalid TIN'
}); });
@ -93,6 +93,16 @@ module.exports = Self => {
done(); done();
} }
Self.validateAsync('fi', validationNIF, {
message: 'El NIF es incorrecto por el Vies'
});
async function validationNIF(err, done){
if (!validateNIF(this.fi, this.isVies, this.countryFk))
err();
done();
}
Self.validateAsync('fi', tinIsValid, { Self.validateAsync('fi', tinIsValid, {
message: 'Invalid TIN' message: 'Invalid TIN'
}); });