From aec46bb8559742ffda56babd2aab418782362956 Mon Sep 17 00:00:00 2001 From: Joan Sanchez Date: Thu, 25 Apr 2019 13:32:14 +0200 Subject: [PATCH] fix send notification to salesPerson #1382 --- .../back/methods/claim/regularizeClaim.js | 33 ++++++++----------- 1 file changed, 13 insertions(+), 20 deletions(-) diff --git a/modules/claim/back/methods/claim/regularizeClaim.js b/modules/claim/back/methods/claim/regularizeClaim.js index 8a897ba5c..8ae47a3fa 100644 --- a/modules/claim/back/methods/claim/regularizeClaim.js +++ b/modules/claim/back/methods/claim/regularizeClaim.js @@ -70,14 +70,16 @@ module.exports = Self => { discount: 100 }, {transaction: transaction}); - await sendMessage(ctx, { - itemFk: sale.itemFk, - ticketFk: sale.ticketFk, - recipientFk: sale.item().itemType().worker().userFk, - quantity: sale.quantity, - concept: sale.concept, - nickname: address.nickname - }, transaction); + if (sale.ticket().client().salesPerson()) { + await sendMessage(ctx, { + itemFk: sale.itemFk, + ticketFk: sale.ticketFk, + recipientFk: sale.ticket().client().salesPerson().userFk, + quantity: sale.quantity, + concept: sale.concept, + nickname: address.nickname + }, transaction); + } } let claim = await Self.findById(params.claimFk); @@ -99,23 +101,14 @@ module.exports = Self => { include: [ { relation: 'ticket', - scope: {fields: ['warehouseFk', 'companyFk']} - }, - { - relation: 'item', scope: { - fields: ['typeFk'], + fields: ['clientFk', 'warehouseFk', 'companyFk'], include: { - relation: 'itemType', + relation: 'client', scope: { - fields: ['workerFk'], include: { - relation: 'worker', - scope: { - fields: ['id', 'userFk'], - } + relation: 'salesPerson' } - } } }