Iban validation for french clients desactivated

This commit is contained in:
gerard 2018-07-27 15:13:01 +02:00
parent ddc6b9d77e
commit 97cbb4fb25
1 changed files with 17 additions and 5 deletions

View File

@ -40,12 +40,24 @@ module.exports = Self => {
min: 3, max: 10
});
var validateIban = require('../validations/validateIban');
Self.validateBinded('iban', validateIban, {
message: 'The IBAN does not have the correct format',
allowNull: true, // FIXME: Ignored by loopback when it's false
allowBlank: true
Self.validateAsync('iban', ibanNeedsValidation, {
message: 'The IBAN does not have the correct format'
});
var validateIban = require('../validations/validateIban');
async function ibanNeedsValidation(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 === 'fr')
return done();
if (!validateIban(this.iban))
err();
done();
}
Self.validateAsync('fi', tinIsValid, {
message: 'Invalid TIN'