refs #6143 refactor: ibanValidation with countryCode param
gitea/salix/pipeline/head There was a failure building this commit Details

This commit is contained in:
Javi Gallego 2023-08-22 14:58:26 +02:00
parent 5690d9bd72
commit 4657bf4e43
3 changed files with 8 additions and 12 deletions

View File

@ -1,6 +1,7 @@
module.exports = function(iban) {
module.exports = function(iban, countryCode) {
if (iban == null) return true;
if (typeof iban != 'string') return false;
if (countryCode?.toLowerCase() != 'es') return true;
iban = iban.toUpperCase();
iban = trim(iban);

View File

@ -90,16 +90,14 @@ module.exports = Self => {
});
async function ibanNeedsValidation(err, done) {
const bankEntity = await Self.app.models.BankEntity.findById(this.bankEntityFk);
const filter = {
fields: ['code'],
where: {id: this.countryFk}
where: {id: bankEntity.countryFk}
};
const country = await Self.app.models.Country.findOne(filter);
const code = country ? country.code.toLowerCase() : null;
if (code != 'es')
return done();
if (!validateIban(this.iban))
if (!validateIban(this.iban, country?.code))
err();
done();
}

View File

@ -7,18 +7,15 @@ module.exports = Self => {
});
async function ibanValidation(err, done) {
const supplier = await Self.app.models.Supplier.findById(this.supplierFk);
const bankEntity = await Self.app.models.BankEntity.findById(this.bankEntityFk);
const filter = {
fields: ['code'],
where: {id: supplier.countryFk}
where: {id: bankEntity.countryFk}
};
const country = await Self.app.models.Country.findOne(filter);
const code = country ? country.code.toLowerCase() : null;
if (code != 'es')
return done();
if (!validateIban(this.iban))
if (!validateIban(this.iban, country?.code))
err();
done();
}