From 29093d7d30e98083c36ee81bebb5c5ed95453020 Mon Sep 17 00:00:00 2001 From: vicent Date: Thu, 20 Oct 2022 14:25:55 +0200 Subject: [PATCH] =?UTF-8?q?feat:=20en=20vez=20de=20consultar=20si=20el=20u?= =?UTF-8?q?suario=20est=C3=A1=20en=20la=20tabla=20workerMana,=20consultar?= =?UTF-8?q?=20es=20si=20el=20usuario=20est=C3=A1=20en=20un=20departamento?= =?UTF-8?q?=20que=20cuelga=20de=20ventas?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../back/methods/sale/specs/updatePrice.spec.js | 11 ++++++++++- modules/ticket/back/methods/sale/updatePrice.js | 8 ++++++-- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/modules/ticket/back/methods/sale/specs/updatePrice.spec.js b/modules/ticket/back/methods/sale/specs/updatePrice.spec.js index e76511421..75be665fb 100644 --- a/modules/ticket/back/methods/sale/specs/updatePrice.spec.js +++ b/modules/ticket/back/methods/sale/specs/updatePrice.spec.js @@ -79,10 +79,19 @@ describe('sale updatePrice()', () => { const price = 5.4; const originalSalesPersonMana = await models.WorkerMana.findById(18, null, options); const manaComponent = await models.Component.findOne({where: {code: 'mana'}}, options); + const teamCLopez = 96; + const userId = 18; + await models.Sale.rawSql(`UPDATE vn.business b + JOIN vn.department d ON d.id = b.departmentFk + SET b.departmentFk = ? + WHERE b.id = ?`, [teamCLopez, userId]); await models.Sale.updatePrice(ctx, saleId, price, options); const updatedSale = await models.Sale.findById(saleId, null, options); - createdSaleComponent = await models.SaleComponent.findOne({where: {saleFk: saleId, componentFk: manaComponent.id}}, options); + const createdSaleComponent = await models.SaleComponent.findOne({ + where: { + saleFk: saleId, componentFk: manaComponent.id + }}, options); expect(updatedSale.price).toBe(price); expect(createdSaleComponent.value).toEqual(-2.04); diff --git a/modules/ticket/back/methods/sale/updatePrice.js b/modules/ticket/back/methods/sale/updatePrice.js index bbd9d154d..dbd4ed091 100644 --- a/modules/ticket/back/methods/sale/updatePrice.js +++ b/modules/ticket/back/methods/sale/updatePrice.js @@ -77,7 +77,12 @@ module.exports = Self => { const oldPrice = sale.price; const userId = ctx.req.accessToken.userId; - const usesMana = await models.WorkerMana.findOne({where: {workerFk: userId}, fields: 'amount'}, myOptions); + + const salesDepartment = await models.Department.findOne({where: {code: 'VT'}, fields: 'id'}, myOptions); + const departments = await models.Department.getLeaves(salesDepartment.id, null, myOptions); + const workerDepartment = await models.WorkerDepartment.findById(userId); + const usesMana = departments.find(department => department.id == workerDepartment.departmentFk); + const componentCode = usesMana ? 'mana' : 'buyerDiscount'; const discount = await models.Component.findOne({where: {code: componentCode}}, myOptions); const componentId = discount.id; @@ -88,7 +93,6 @@ module.exports = Self => { saleFk: id }; const saleComponent = await models.SaleComponent.findOne({where}, myOptions); - if (saleComponent) { await models.SaleComponent.updateAll(where, { value: saleComponent.value + componentValue