From 0d980334b8da9ed54ba71e9f1f1b2a99ea14096a Mon Sep 17 00:00:00 2001 From: alexandre Date: Wed, 17 May 2023 12:41:00 +0200 Subject: [PATCH] refs #5634 conditional merge --- modules/ticket/back/methods/ticket/merge.js | 7 ++++--- modules/ticket/back/methods/ticket/setDeleted.js | 3 +++ 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/modules/ticket/back/methods/ticket/merge.js b/modules/ticket/back/methods/ticket/merge.js index 8aaca1085..9a6f859f7 100644 --- a/modules/ticket/back/methods/ticket/merge.js +++ b/modules/ticket/back/methods/ticket/merge.js @@ -63,10 +63,11 @@ module.exports = Self => { newInstance: {mergedTicket: ticket.originId} }; - await models.TicketLog.create(ticketDestinationLogRecord, myOptions); await models.Sale.updateAll({ticketFk: ticket.originId}, {ticketFk: ticket.destinationId}, myOptions); - await models.Ticket.setDeleted(ctx, ticket.originId, myOptions); - await models.Chat.sendCheckingPresence(ctx, ticket.workerFk, message); + if (await models.Ticket.setDeleted(ctx, ticket.originId, myOptions)) { + await models.TicketLog.create(ticketDestinationLogRecord, myOptions); + await models.Chat.sendCheckingPresence(ctx, ticket.workerFk, message); + } } if (tx) await tx.commit(); diff --git a/modules/ticket/back/methods/ticket/setDeleted.js b/modules/ticket/back/methods/ticket/setDeleted.js index 2889160d1..8c7f9d546 100644 --- a/modules/ticket/back/methods/ticket/setDeleted.js +++ b/modules/ticket/back/methods/ticket/setDeleted.js @@ -36,6 +36,9 @@ module.exports = Self => { } try { + const ticketToDelete = await models.Ticket.findById(id, {fields: ['isDeleted']}, myOptions); + if (ticketToDelete.isDeleted) return false; + const userId = ctx.req.accessToken.userId; const isEditable = await Self.isEditable(ctx, id, myOptions);