From 052c51cee55e9b856ae599baf6652082c1e7c18a Mon Sep 17 00:00:00 2001 From: Joan Sanchez Date: Mon, 1 Jun 2020 12:47:04 +0200 Subject: [PATCH] 2282 - Change stowaway state to FIXING --- .../ticket/back/methods/ticket/setDeleted.js | 22 ++++++++++++++++-- .../methods/ticket/specs/setDeleted.spec.js | 23 +++++++++++++++++++ 2 files changed, 43 insertions(+), 2 deletions(-) diff --git a/modules/ticket/back/methods/ticket/setDeleted.js b/modules/ticket/back/methods/ticket/setDeleted.js index 0f7e0b57f3..86fb89e4d8 100644 --- a/modules/ticket/back/methods/ticket/setDeleted.js +++ b/modules/ticket/back/methods/ticket/setDeleted.js @@ -83,7 +83,7 @@ module.exports = Self => { } const ticket = await models.Ticket.findById(id, { - include: { + include: [{ relation: 'client', scope: { fields: ['id', 'salesPersonFk'], @@ -97,9 +97,27 @@ module.exports = Self => { } } } - } + }, { + relation: 'ship' + }, { + relation: 'stowaway' + }] }); + // Change state to "fixing" if contains an stowaway + let otherTicketId; + if (ticket.stowaway()) + otherTicketId = ticket.stowaway().shipFk; + else if (ticket.ship()) + otherTicketId = ticket.ship().id; + + if (otherTicketId) { + models.TicketTracking.changeState(ctx, { + ticketFk: otherTicketId, + code: 'FIXING' + }); + } + // Send notification to salesPerson const salesPerson = ticket.client().salesPerson(); if (salesPerson) { diff --git a/modules/ticket/back/methods/ticket/specs/setDeleted.spec.js b/modules/ticket/back/methods/ticket/specs/setDeleted.spec.js index 2713bd700e..990e69fa9c 100644 --- a/modules/ticket/back/methods/ticket/specs/setDeleted.spec.js +++ b/modules/ticket/back/methods/ticket/specs/setDeleted.spec.js @@ -103,4 +103,27 @@ describe('ticket deleted()', () => { expect(error.translateArgs[0]).toEqual(2); expect(error.message).toEqual('You must delete the claim id %d first'); }); + + fit('should delete the ticket and change the state to "FIXING" to the stowaway ticket', async() => { + const ticketId = 16; + const ctx = { + req: { + accessToken: {userId: 106}, + headers: { + origin: 'http://localhost:5000' + }, + __: () => {} + } + }; + let error; + + try { + await app.models.Ticket.setDeleted(ctx, ticketId); + } catch (e) { + error = e; + } + + expect(error.translateArgs[0]).toEqual(2); + expect(error.message).toEqual('You must delete the claim id %d first'); + }); });