From b871615e8f5a701cea63a20ae2d1818fe3b435ed Mon Sep 17 00:00:00 2001 From: alexm Date: Tue, 16 Jul 2024 10:42:08 +0200 Subject: [PATCH] fix: worker new if not has provinceFk --- modules/worker/back/methods/worker/new.js | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/modules/worker/back/methods/worker/new.js b/modules/worker/back/methods/worker/new.js index fad464ae1..bb43fba99 100644 --- a/modules/worker/back/methods/worker/new.js +++ b/modules/worker/back/methods/worker/new.js @@ -193,9 +193,13 @@ module.exports = Self => { } await user.updateAttribute('email', email, myOptions); - const {countryFk} = await Self.app.models.Province.findById(provinceFk, { - fields: ['countryFk'] - }); + let countryFk; + if (provinceFk) { + const province = await Self.app.models.Province.findById(provinceFk, { + fields: ['countryFk'] + }); + countryFk = province.countryFk; + } await models.Worker.create({ id: user.id, firstName, @@ -205,7 +209,6 @@ module.exports = Self => { fi, birth, originCountryFk: countryFk - }, myOptions); if (tx) await tx.commit();