From 52d62710e6347cc2b8e8d6ab8fb49effaf663757 Mon Sep 17 00:00:00 2001 From: jorgep Date: Tue, 13 Aug 2024 13:49:00 +0200 Subject: [PATCH] chore: refs #7663 fix logic --- .../ticket/back/methods/ticket/setWeight.js | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/modules/ticket/back/methods/ticket/setWeight.js b/modules/ticket/back/methods/ticket/setWeight.js index f2a65b1d6..4f9e1883e 100644 --- a/modules/ticket/back/methods/ticket/setWeight.js +++ b/modules/ticket/back/methods/ticket/setWeight.js @@ -16,13 +16,17 @@ module.exports = Self => { required: true, description: 'The weight value', }], + returns: { + type: 'boolean', + root: true + }, http: { path: `/:id/setWeight`, verb: 'POST' } }); - Self.setWeight = async(ctx, ticketId, weight, invoiceable, options) => { + Self.setWeight = async(ctx, ticketId, weight, options) => { const models = Self.app.models; const userId = ctx.req.accessToken.userId; const myOptions = {userId}; @@ -36,10 +40,10 @@ module.exports = Self => { } try { + const ticket = await Self.findById(ticketId, null, myOptions); if (ticket.weight) throw new UserError('Weight already set'); const canEdit = await models.ACL.checkAccessAcl(ctx, 'Ticket', 'updateAttributes'); - const ticket = await Self.findById(ticketId, null, myOptions); const client = await models.Client.findById(ticket.clientFk, { include: {relation: 'salesPersonUser'}}, myOptions); @@ -51,7 +55,10 @@ module.exports = Self => { where: {workerFk: {inq: [userId, salesPersonUser.id]}} }, myOptions); - if (workerDepartments[0].departmentFk != workerDepartments[1].departmentFk) + if ( + workerDepartments.length == 2 && + workerDepartments[0].departmentFk != workerDepartments[1].departmentFk + ) throw new UserError('You don\'t have enough privileges'); } @@ -63,10 +70,12 @@ module.exports = Self => { const [{taxArea}] = await Self.rawSql('SELECT clientTaxArea(?,?) taxArea', [ticket.clientFk, ticket.warehouseFk], myOptions); - if (ticketState.alertLevel >= packedState.alertLevel && taxArea == 'WORLD' && client.hasDailyInvoice) + if (ticketState.alertLevel >= packedState.alertLevel && taxArea == 'WORLD' && client.hasDailyInvoice) { await Self.invoiceTicketsAndPdf(ctx, [ticketId], null, myOptions); - + return true; + } if (tx) await tx.commit(); + return false; } catch (e) { if (tx) await tx.rollback(); throw e;