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