From 6416891918354820969fa2c0768b2a6a04976531 Mon Sep 17 00:00:00 2001 From: carlossa Date: Wed, 13 Dec 2023 13:55:31 +0100 Subject: [PATCH] refs #6291 tinIsValid worker --- back/models/vn-user.js | 22 ------------------- .../08-route/03_create_and_clone.spec.js | 2 +- modules/worker/back/models/worker.js | 19 ++++++++++++++++ 3 files changed, 20 insertions(+), 23 deletions(-) diff --git a/back/models/vn-user.js b/back/models/vn-user.js index 5ab0c755e..de5bf7b63 100644 --- a/back/models/vn-user.js +++ b/back/models/vn-user.js @@ -2,7 +2,6 @@ const vnModel = require('vn-loopback/common/models/vn-model'); const {Email} = require('vn-print'); const ForbiddenError = require('vn-loopback/util/forbiddenError'); const LoopBackContext = require('loopback-context'); -const validateTin = require('vn-loopback/util/validateTin'); module.exports = function(Self) { vnModel(Self); @@ -20,27 +19,6 @@ module.exports = function(Self) { // Validations - Self.validateAsync('fi', tinIsValid, { - message: 'Invalid TIN' - }); - - async function tinIsValid(err, done) { - if (!this.isTaxDataChecked) - return done(); - - const filter = { - fields: ['code'], - where: {id: this.countryFk} - }; - const country = await Self.app.models.Country.findOne(filter); - const code = country ? country.code.toLowerCase() : null; - const countryCode = this.fi?.toLowerCase().substring(0, 2); - - if (!this.fi || !validateTin(this.fi, code) || (this.isVies && countryCode == code)) - err(); - done(); - } - Self.validatesFormatOf('email', { message: 'Invalid email', allowNull: true, diff --git a/e2e/paths/08-route/03_create_and_clone.spec.js b/e2e/paths/08-route/03_create_and_clone.spec.js index 0b8da98b4..31c0cfc18 100644 --- a/e2e/paths/08-route/03_create_and_clone.spec.js +++ b/e2e/paths/08-route/03_create_and_clone.spec.js @@ -26,7 +26,7 @@ describe('Route create path', () => { await page.waitToClick(selectors.createRouteView.submitButton); const message = await page.waitForSnackbar(); - expect(message.text).toContain('Access denied'); + expect(message.text).toContain('Access Denied'); }); }); diff --git a/modules/worker/back/models/worker.js b/modules/worker/back/models/worker.js index 985d83e9f..48ff1da12 100644 --- a/modules/worker/back/models/worker.js +++ b/modules/worker/back/models/worker.js @@ -1,4 +1,5 @@ module.exports = Self => { + const validateTin = require('vn-loopback/util/validateTin'); require('../methods/worker/filter')(Self); require('../methods/worker/mySubordinates')(Self); require('../methods/worker/isSubordinate')(Self); @@ -23,4 +24,22 @@ module.exports = Self => { Self.validatesUniquenessOf('locker', { message: 'This locker has already been assigned' }); + + Self.validateAsync('fi', tinIsValid, { + message: 'Invalid TIN' + }); + + async function tinIsValid(err, done) { + const filter = { + fields: ['code'], + where: {id: this.countryFk} + }; + const country = await Self.app.models.Country.findOne(filter); + const code = country ? country.code.toLowerCase() : null; + const countryCode = this.fi?.toLowerCase().substring(0, 2); + + if (!this.fi || !validateTin(this.fi, code) || (this.isVies && countryCode == code)) + err(); + done(); + } };