From 6a78ac46c7b08305edc0aa71e8956cb653c16bb0 Mon Sep 17 00:00:00 2001 From: alexm Date: Thu, 23 Dec 2021 08:53:56 +0100 Subject: [PATCH] fix(client): check businesTypeFk before clientCredit insert --- modules/client/back/models/client.js | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/modules/client/back/models/client.js b/modules/client/back/models/client.js index b4961771d..7ab8bb477 100644 --- a/modules/client/back/models/client.js +++ b/modules/client/back/models/client.js @@ -374,11 +374,14 @@ module.exports = Self => { throw new UserError(`You don't have enough privileges to set this credit amount`); } - await models.ClientCredit.create({ - amount: changes.credit, - clientFk: finalState.id, - workerFk: userId - }, ctx.options); + const client = await models.Client.findById(finalState.id, null, ctx.options); + if (client.businessTypeFk) { + await models.ClientCredit.create({ + amount: changes.credit, + clientFk: finalState.id, + workerFk: userId + }, ctx.options); + } }; const app = require('vn-loopback/server/server');