From 0e0db960afcd3aa0e921823387fb3acca986bdf1 Mon Sep 17 00:00:00 2001 From: carlossa Date: Fri, 28 Apr 2023 14:23:44 +0200 Subject: [PATCH] refs #5540 supplier --- loopback/util/validateNIF.js | 14 ------------ modules/client/back/models/client.js | 33 ++++++---------------------- 2 files changed, 7 insertions(+), 40 deletions(-) delete mode 100644 loopback/util/validateNIF.js diff --git a/loopback/util/validateNIF.js b/loopback/util/validateNIF.js deleted file mode 100644 index 041ca8876..000000000 --- a/loopback/util/validateNIF.js +++ /dev/null @@ -1,14 +0,0 @@ -const models = require('vn-loopback/server/server').models; -module.exports = async function(fi, isVies, countryFk) { - const filter = { - fields: ['code'], - where: {id: countryFk} - }; - const countryCode = fi.toUpperCase().substring(0, 2); - const country = await models.Country.findOne(filter); - const code = country ? country.code : null; - if (isVies && countryCode == code) - return false; - return true; -}; - diff --git a/modules/client/back/models/client.js b/modules/client/back/models/client.js index e04c4478f..c95d0972f 100644 --- a/modules/client/back/models/client.js +++ b/modules/client/back/models/client.js @@ -4,7 +4,7 @@ const isMultiple = require('vn-loopback/util/hook').isMultiple; const validateTin = require('vn-loopback/util/validateTin'); const validateIban = require('vn-loopback/util/validateIban'); const LoopBackContext = require('loopback-context'); -const validateNIF = require('vn-loopback/util/validateNIF'); +const { ConsoleReporter } = require('jasmine'); module.exports = Self => { // Methods @@ -24,19 +24,6 @@ module.exports = Self => { message: 'TIN must be unique' }); - async function fiInvalid(err, done) { - const filter = { - fields: ['code'], - where: {id: this.countryFk} - }; - const countryCode = this.fi.toUpperCase().substring(0, 2); - const country = await Self.app.models.Country.findOne(filter); - const code = country ? country.code : null; - if (this.isVies && countryCode == code) - err(); - done(); - } - Self.validatesFormatOf('email', { message: 'Invalid email', allowNull: true, @@ -89,16 +76,6 @@ module.exports = Self => { done(); } - Self.validateAsync('fi', validationNIF, { - message: 'El NIF es incorrecto por el Vies' - }); - - async function validationNIF(err, done){ - if (!validateNIF(this.fi, this.isVies, this.countryFk)) - err(); - done(); - } - Self.validateAsync('fi', tinIsValid, { message: 'Invalid TIN' }); @@ -112,9 +89,13 @@ module.exports = Self => { where: {id: this.countryFk} }; const country = await Self.app.models.Country.findOne(filter); + console.log(country); const code = country ? country.code.toLowerCase() : null; - - if (!this.fi || !validateTin(this.fi, code)) + console.log(code); + const countryCode = this.fi.toLowerCase().substring(0, 2); + console.log(countryCode); + + if (!this.fi || !validateTin(this.fi, code) || (this.isVies && countryCode == code)) err(); done(); }