From 2279b3d9ab42953b90b6a8a3dd006404e90b1a29 Mon Sep 17 00:00:00 2001 From: joan Date: Wed, 5 Jan 2022 15:17:21 +0100 Subject: [PATCH] Prevent businessTypeFk validation for other invalid fields --- modules/client/back/models/client.js | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/modules/client/back/models/client.js b/modules/client/back/models/client.js index 06453da36..0c378ec25 100644 --- a/modules/client/back/models/client.js +++ b/modules/client/back/models/client.js @@ -184,15 +184,17 @@ module.exports = Self => { const changes = ctx.data || ctx.instance; const orgData = ctx.currentInstance; - const businessTypeFk = changes && changes.businessTypeFk || orgData && orgData.businessTypeFk; - const isTaxDataChecked = changes && changes.isTaxDataChecked || orgData && orgData.isTaxDataChecked; + if (!ctx.isNewInstance) { + const businessTypeFk = changes && changes.businessTypeFk || orgData && orgData.businessTypeFk; + const isTaxDataChecked = changes && changes.isTaxDataChecked || orgData && orgData.isTaxDataChecked; + const changedFields = Object.keys(changes); + const hasChangedOtherFields = changedFields.some(key => key !== 'businessTypeFk'); - let isWorker = false; - if (!ctx.isNewInstance) - isWorker = await Self.app.models.UserAccount.findById(orgData.id); + const isWorker = await Self.app.models.UserAccount.findById(orgData.id); - if (!businessTypeFk && !isTaxDataChecked && !isWorker) - throw new UserError(`The type of business must be filled in basic data`); + if (!businessTypeFk && !isTaxDataChecked && !isWorker && !hasChangedOtherFields) + throw new UserError(`The type of business must be filled in basic data`); + } }); Self.observe('before save', async function(ctx) {