diff --git a/loopback/locale/en.json b/loopback/locale/en.json index b8c31020bc..dc62e35f43 100644 --- a/loopback/locale/en.json +++ b/loopback/locale/en.json @@ -62,6 +62,7 @@ "MESSAGE_INSURANCE_CHANGE": "I have changed the insurence credit of client [{{clientName}} (#{{clientId}})]({{{url}}}) to *{{credit}} €*", "MESSAGE_CHANGED_PAYMETHOD": "I have changed the pay method for client [{{clientName}} (#{{clientId}})]({{{url}}})", "Sent units from ticket": "I sent *{{quantity}}* units of [{{concept}} (#{{itemId}})]({{{itemUrl}}}) to *\"{{nickname}}\"* coming from ticket id [#{{ticketId}}]({{{ticketUrl}}})", + "This ticket is not an stowaway anymore": "The ticket id [#{{ticketId}}]({{{ticketUrl}}}) is not an stowaway anymore", "Customs agent is required for a non UEE member": "Customs agent is required for a non UEE member", "Incoterms is required for a non UEE member": "Incoterms is required for a non UEE member", "Client checked as validated despite of duplication": "Client checked as validated despite of duplication from client id {{clientId}}", diff --git a/loopback/locale/es.json b/loopback/locale/es.json index 5f41c9931c..da62a6a7d9 100644 --- a/loopback/locale/es.json +++ b/loopback/locale/es.json @@ -125,6 +125,7 @@ "MESSAGE_INSURANCE_CHANGE": "He cambiado el crédito asegurado del cliente [{{clientName}} (#{{clientId}})]({{{url}}}) a *{{credit}} €*", "MESSAGE_CHANGED_PAYMETHOD": "He cambiado la forma de pago del cliente [{{clientName}} (#{{clientId}})]({{{url}}})", "Sent units from ticket": "Envio *{{quantity}}* unidades de [{{concept}} (#{{itemId}})]({{{itemUrl}}}) a *\"{{nickname}}\"* provenientes del ticket id [#{{ticketId}}]({{{ticketUrl}}})", + "This ticket is not an stowaway anymore": "El ticket id [#{{ticketId}}]({{{ticketUrl}}}) ha dejado de ser un polizón", "Client checked as validated despite of duplication": "Cliente comprobado a pesar de que existe el cliente id {{clientId}}", "ORDER_ROW_UNAVAILABLE": "No hay disponibilidad de este producto", "Distance must be lesser than 1000": "La distancia debe ser inferior a 1000", diff --git a/modules/ticket/back/methods/ticket/deleteStowaway.js b/modules/ticket/back/methods/ticket/deleteStowaway.js index 6f3a1760ff..cf9626c14c 100644 --- a/modules/ticket/back/methods/ticket/deleteStowaway.js +++ b/modules/ticket/back/methods/ticket/deleteStowaway.js @@ -1,6 +1,6 @@ module.exports = Self => { - Self.remoteMethod('deleteStowaway', { + Self.remoteMethodCtx('deleteStowaway', { description: 'Deletes an stowaway', accessType: 'WRITE', accepts: [{ @@ -19,21 +19,66 @@ module.exports = Self => { } }); - Self.deleteStowaway = async id => { + Self.deleteStowaway = async(ctx, id) => { + const models = Self.app.models; + const $t = ctx.req.__; // $translate const ticket = await Self.findById(id, { include: [{ relation: 'ship' }, { relation: 'stowaway' + }, { + relation: 'client', + scope: { + include: { + relation: 'salesPerson' + } + } }] }); - let params; - if (ticket.stowaway()) - params = [ticket.stowaway().shipFk, ticket.stowaway().id]; - else if (ticket.ship()) - params = [ticket.ship().shipFk, ticket.ship().id]; + let stowawayFk; + let shipFk; + if (ticket.stowaway()) { + shipFk = ticket.stowaway().shipFk; + stowawayFk = ticket.stowaway().id; + } else if (ticket.ship()) { + shipFk = ticket.ship().shipFk; + stowawayFk = ticket.ship().id; + } - return Self.rawSql(`CALL vn.stowaway_unboarding(?, ?)`, params); + const stowaway = await models.Stowaway.findOne({ + where: { + id: stowawayFk, + shipFk: shipFk + } + }); + const result = await stowaway.destroy(); + + const state = await models.State.findOne({ + where: { + code: 'BOARDING' + } + }); + const ticketTracking = await models.TicketTracking.findOne({ + where: { + ticketFk: shipFk, + stateFk: state.id + } + }); + + await ticketTracking.destroy(); + + const salesPerson = ticket.client().salesPerson(); + if (salesPerson) { + const origin = ctx.req.headers.origin; + const message = $t('This ticket is not an stowaway anymore', { + ticketId: stowawayFk, + ticketUrl: `${origin}/#!/ticket/${stowawayFk}/summary` + }); + await models.Chat.sendCheckingPresence(ctx, salesPerson.id, message); + } + + return result; }; };