salix/modules/supplier/back/models/supplier-account.js

23 lines
630 B
JavaScript
Raw Normal View History

2021-04-01 15:36:27 +00:00
const validateIban = require('vn-loopback/util/validateIban');
module.exports = Self => {
2021-04-16 16:35:03 +00:00
Self.validateAsync('iban', ibanValidation, {
2021-04-01 15:36:27 +00:00
message: 'The IBAN does not have the correct format'
});
2021-04-16 16:35:03 +00:00
async function ibanValidation(err, done) {
2021-04-01 15:36:27 +00:00
let filter = {
fields: ['code'],
where: {id: this.countryFk}
};
let country = await Self.app.models.Country.findOne(filter);
let code = country ? country.code.toLowerCase() : null;
if (code != 'es')
return done();
if (!validateIban(this.iban))
err();
done();
}
};