23 lines
630 B
JavaScript
23 lines
630 B
JavaScript
const validateIban = require('vn-loopback/util/validateIban');
|
|
|
|
module.exports = Self => {
|
|
Self.validateAsync('iban', ibanValidation, {
|
|
message: 'The IBAN does not have the correct format'
|
|
});
|
|
|
|
async function ibanValidation(err, done) {
|
|
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();
|
|
}
|
|
};
|