diff --git a/e2e/paths/06-claim-module/04_claim_action.spec.js b/e2e/paths/06-claim-module/04_claim_action.spec.js index 82338d15b7..5bf6ed3d2a 100644 --- a/e2e/paths/06-claim-module/04_claim_action.spec.js +++ b/e2e/paths/06-claim-module/04_claim_action.spec.js @@ -13,7 +13,6 @@ describe('Claim action path', () => { it('should import the claim', async() => { const result = await nightmare - .wait(1000) .waitToClick(selectors.claimAction.importClaimButton) .waitForLastSnackbar(); @@ -22,7 +21,6 @@ describe('Claim action path', () => { it('should import the second importable ticket', async() => { const result = await nightmare - .wait(1000) .waitToClick(selectors.claimAction.importTicketButton) .waitToClick(selectors.claimAction.secondImportableTicket) .waitForLastSnackbar(); diff --git a/modules/invoiceOut/back/methods/invoiceOut/delete.js b/modules/invoiceOut/back/methods/invoiceOut/delete.js index 5700669c78..127786ded4 100644 --- a/modules/invoiceOut/back/methods/invoiceOut/delete.js +++ b/modules/invoiceOut/back/methods/invoiceOut/delete.js @@ -21,9 +21,9 @@ module.exports = Self => { }); Self.delete = async id => { - const tx = await Self.beginTransaction({}); + const transaction = await Self.beginTransaction({}); try { - let options = {transaction: tx}; + let options = {transaction: transaction}; let invoiceOut = await Self.findById(id); let tickets = await Self.app.models.Ticket.find({where: {refFk: invoiceOut.ref}}); @@ -35,10 +35,10 @@ module.exports = Self => { await Promise.all(promises); await invoiceOut.destroy(options); - await tx.commit(); + await transaction.commit(); return tickets; } catch (e) { - await tx.rollback(); + await transaction.rollback(); throw e; } }; diff --git a/modules/ticket/back/methods/ticket/delete.js b/modules/ticket/back/methods/ticket/delete.js index bca9e04281..c44c8d3e47 100644 --- a/modules/ticket/back/methods/ticket/delete.js +++ b/modules/ticket/back/methods/ticket/delete.js @@ -22,19 +22,24 @@ module.exports = Self => { }); Self.delete = async(ctx, params) => { - let claimOfATicket = await Self.app.models.Claim.findOne({where: {ticketFk: params.id}}); - if (claimOfATicket) - throw new UserError('You must delete the claim id %d first', 'DELETE_CLAIM_FIRST', claimOfATicket.id); + const transaction = await Self.beginTransaction({}); + try { + let claimOfATicket = await Self.app.models.Claim.findOne({where: {ticketFk: params.id}}); + if (claimOfATicket) + throw new UserError('You must delete the claim id %d first', 'DELETE_CLAIM_FIRST', claimOfATicket.id); - let currentTicket = await Self.app.models.Ticket.findById(params.id); - await currentTicket.updateAttributes({isDeleted: true}); + let currentTicket = await Self.app.models.Ticket.findById(params.id); + await currentTicket.updateAttributes({isDeleted: true}); - let userId = ctx.req.accessToken.userId; - let worker = await Self.app.models.Worker.findOne({where: {userFk: userId}}); - params.workerFk = worker.id; - let state = await Self.app.models.State.findOne({where: {code: 'ERASED'}}); + let userId = ctx.req.accessToken.userId; + let worker = await Self.app.models.Worker.findOne({where: {userFk: userId}}); + params.workerFk = worker.id; + let state = await Self.app.models.State.findOne({where: {code: 'ERASED'}}); - - return await Self.app.models.TicketTracking.create({ticketFk: params.id, stateFk: state.id, workerFk: params.workerFk}); + return await Self.app.models.TicketTracking.create({ticketFk: params.id, stateFk: state.id, workerFk: params.workerFk}); + } catch (e) { + await transaction.rollback(); + throw e; + } }; };