From 97cbb4fb25502a9c70f23fb1d9c62f2adefa63fb Mon Sep 17 00:00:00 2001 From: gerard Date: Fri, 27 Jul 2018 15:13:01 +0200 Subject: [PATCH] Iban validation for french clients desactivated --- services/loopback/common/models/client.js | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/services/loopback/common/models/client.js b/services/loopback/common/models/client.js index c9c7cec00..9a246fac1 100644 --- a/services/loopback/common/models/client.js +++ b/services/loopback/common/models/client.js @@ -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'