From 896d273da81d0eb99331f759d5f26f72c24accd6 Mon Sep 17 00:00:00 2001 From: alexm Date: Fri, 12 Jul 2024 12:06:37 +0200 Subject: [PATCH] fix(worker_new): fix countryFk --- modules/client/front/postcode/index.html | 2 +- modules/worker/back/methods/worker/new.js | 12 ++++++------ modules/worker/back/models/worker.js | 7 +++---- 3 files changed, 10 insertions(+), 11 deletions(-) diff --git a/modules/client/front/postcode/index.html b/modules/client/front/postcode/index.html index b3dbb74d8..fa0b7870f 100644 --- a/modules/client/front/postcode/index.html +++ b/modules/client/front/postcode/index.html @@ -53,7 +53,7 @@ diff --git a/modules/worker/back/methods/worker/new.js b/modules/worker/back/methods/worker/new.js index ba9dc3853..fad464ae1 100644 --- a/modules/worker/back/methods/worker/new.js +++ b/modules/worker/back/methods/worker/new.js @@ -171,8 +171,8 @@ module.exports = Self => { const address = await models.Address.create({ clientFk: user.id, street: street, - city: city, - provinceFk: provinceFk, + city, + provinceFk, postalCode: postcode, mobile: phone, nickname: nickname, @@ -193,7 +193,9 @@ module.exports = Self => { } await user.updateAttribute('email', email, myOptions); - + const {countryFk} = await Self.app.models.Province.findById(provinceFk, { + fields: ['countryFk'] + }); await models.Worker.create({ id: user.id, firstName, @@ -202,6 +204,7 @@ module.exports = Self => { bossFk, fi, birth, + originCountryFk: countryFk }, myOptions); @@ -212,11 +215,8 @@ module.exports = Self => { const message = e.sqlMessage; if (e.message && e.message.includes(`Email already exists`)) throw new UserError(`This personal mail already exists`); - if (code === 'ER_DUP_ENTRY' && message.includes(`CodigoTrabajador_UNIQUE`)) throw new UserError(`This worker code already exists`); - if (code === 'ER_DUP_ENTRY' && message.includes(`PRIMARY`)) throw new UserError(`This worker already exists`); - throw e; } diff --git a/modules/worker/back/models/worker.js b/modules/worker/back/models/worker.js index 0b0e043f2..3351c348c 100644 --- a/modules/worker/back/models/worker.js +++ b/modules/worker/back/models/worker.js @@ -27,11 +27,10 @@ module.exports = Self => { }); async function tinIsValid(err, done) { - const filter = { + const country = await Self.app.models.Country.findOne({ fields: ['code'], - where: {id: this.countryFk} - }; - const country = await Self.app.models.Country.findOne(filter); + where: {id: this.originCountryFk} + }); const code = country ? country.code.toLowerCase() : null; if (!this.fi || !validateTin(this.fi, code)) -- 2.40.1