refs #5540 supplier

This commit is contained in:
Carlos Satorres 2023-04-28 14:23:44 +02:00
parent c0deb745d6
commit 0e0db960af
2 changed files with 7 additions and 40 deletions

View File

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

View File

@ -4,7 +4,7 @@ const isMultiple = require('vn-loopback/util/hook').isMultiple;
const validateTin = require('vn-loopback/util/validateTin'); const validateTin = require('vn-loopback/util/validateTin');
const validateIban = require('vn-loopback/util/validateIban'); const validateIban = require('vn-loopback/util/validateIban');
const LoopBackContext = require('loopback-context'); const LoopBackContext = require('loopback-context');
const validateNIF = require('vn-loopback/util/validateNIF'); const { ConsoleReporter } = require('jasmine');
module.exports = Self => { module.exports = Self => {
// Methods // Methods
@ -24,19 +24,6 @@ module.exports = Self => {
message: 'TIN must be unique' 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();
}
Self.validatesFormatOf('email', { Self.validatesFormatOf('email', {
message: 'Invalid email', message: 'Invalid email',
allowNull: true, allowNull: true,
@ -89,16 +76,6 @@ 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'
}); });
@ -112,9 +89,13 @@ module.exports = Self => {
where: {id: this.countryFk} where: {id: this.countryFk}
}; };
const country = await Self.app.models.Country.findOne(filter); const country = await Self.app.models.Country.findOne(filter);
console.log(country);
const code = country ? country.code.toLowerCase() : null; const code = country ? country.code.toLowerCase() : null;
console.log(code);
if (!this.fi || !validateTin(this.fi, code)) const countryCode = this.fi.toLowerCase().substring(0, 2);
console.log(countryCode);
if (!this.fi || !validateTin(this.fi, code) || (this.isVies && countryCode == code))
err(); err();
done(); done();
} }