From a29de13ab364425732847e91c055d12f3d3f689b Mon Sep 17 00:00:00 2001 From: sergiodt Date: Tue, 28 Jan 2025 09:54:26 +0100 Subject: [PATCH] fix: refs #7569 saveSign use smtp.send and fix link --- loopback/locale/en.json | 2 +- loopback/locale/es.json | 2 +- loopback/locale/fr.json | 2 +- loopback/locale/pt.json | 2 +- .../ticket/back/methods/ticket/saveSign.js | 51 +++++++++---------- .../methods/ticket/specs/saveSign.spec.js | 2 +- 6 files changed, 29 insertions(+), 32 deletions(-) diff --git a/loopback/locale/en.json b/loopback/locale/en.json index 06428475f..eeb32f545 100644 --- a/loopback/locale/en.json +++ b/loopback/locale/en.json @@ -253,5 +253,5 @@ "Sales already moved": "Sales already moved", "Holidays to past days not available": "Holidays to past days not available", "Incorrect delivery order alert on route": "Incorrect delivery order alert on route: {{ route }} zone: {{ zone }}", - "Ticket has been delivered out of order": "The ticket {{ticket}} {{{fullUrl}}} has been delivered out of order." + "Ticket has been delivered out of order": "The ticket {{ticket}} of route {{{fullUrl}}} has been delivered out of order." } \ No newline at end of file diff --git a/loopback/locale/es.json b/loopback/locale/es.json index abd2f79a0..2ead6fa10 100644 --- a/loopback/locale/es.json +++ b/loopback/locale/es.json @@ -395,6 +395,6 @@ "All tickets have a route order": "Todos los tickets tienen orden de ruta", "There are tickets to be invoiced": "La zona tiene tickets por facturar", "Incorrect delivery order alert on route": "Alerta de orden de entrega incorrecta en ruta: {{ route }} zona: {{ zone }}", - "Ticket has been delivered out of order": "El ticket {{ticket}} {{{fullUrl}}} no ha sigo entregado en su orden.", + "Ticket has been delivered out of order": "El ticket {{ticket}} de la ruta {{{fullUrl}}} no ha sigo entregado en su orden.", "Price cannot be blank": "El precio no puede estar en blanco" } \ No newline at end of file diff --git a/loopback/locale/fr.json b/loopback/locale/fr.json index d7d5b7710..378b0d267 100644 --- a/loopback/locale/fr.json +++ b/loopback/locale/fr.json @@ -368,5 +368,5 @@ "ticketLostExpedition": "Le ticket [{{ticketId}}]({{{ticketUrl}}}) a l'expédition perdue suivante : {{expeditionId}}", "The web user's email already exists": "L'email de l'internaute existe déjà", "Incorrect delivery order alert on route": "Alerte de bon de livraison incorrect sur l'itinéraire: {{ route }} zone : {{ zone }}", - "Ticket has been delivered out of order": "Le ticket {{ticket}} {{{fullUrl}}} a été livré hors ordre." + "Ticket has been delivered out of order": "Le ticket {{ticket}} de la route {{{fullUrl}}} a été livré hors service." } \ No newline at end of file diff --git a/loopback/locale/pt.json b/loopback/locale/pt.json index d1ac2ef23..35fe3d4f1 100644 --- a/loopback/locale/pt.json +++ b/loopback/locale/pt.json @@ -367,5 +367,5 @@ "ticketLostExpedition": "O ticket [{{ticketId}}]({{{ticketUrl}}}) tem a seguinte expedição perdida: {{expeditionId}}", "The web user's email already exists": "O e-mail do utilizador da web já existe.", "Incorrect delivery order alert on route": "Alerta de ordem de entrega incorreta na rota: {{ route }} zona: {{ zone }}", - "Ticket has been delivered out of order": "O ticket {{ticket}} {{{fullUrl}}} foi entregue fora de ordem." + "Ticket has been delivered out of order": "O ticket {{ticket}} da rota {{{fullUrl}}} foi entregue fora de ordem." } \ No newline at end of file diff --git a/modules/ticket/back/methods/ticket/saveSign.js b/modules/ticket/back/methods/ticket/saveSign.js index f99311c39..93202d042 100644 --- a/modules/ticket/back/methods/ticket/saveSign.js +++ b/modules/ticket/back/methods/ticket/saveSign.js @@ -1,4 +1,5 @@ const UserError = require('vn-loopback/util/user-error'); +const smtp = require('vn-print/core/smtp'); module.exports = Self => { Self.remoteMethodCtx('saveSign', { @@ -31,6 +32,7 @@ module.exports = Self => { Self.saveSign = async(ctx, tickets, location, signedTime, options) => { const models = Self.app.models; const myOptions = {userId: ctx.req.accessToken.userId}; + const url = await Self.app.models.Url.getUrl('lilium'); let tx; let ticket; let dms; @@ -146,11 +148,11 @@ module.exports = Self => { await ticket.updateAttribute('isSigned', true, myOptions); const [{stateCode}] = await Self.rawSql(` - SELECT + SELECT IF((SUM(CASE WHEN est.code = 'DELIVERED' THEN 1 ELSE 0 END) = COUNT(*)), 'DELIVERED','PARTIAL_DELIVERED') stateCode FROM vn.expedition e - JOIN vn.expeditionStateType est ON est.id = e.stateTypeFk + JOIN vn.expeditionStateType est ON est.id = e.stateTypeFk WHERE e.ticketFk = ?; `, [ticketId], myOptions); @@ -167,15 +169,15 @@ module.exports = Self => { FROM ticket t JOIN ticketState ts ON ts.ticketFk = t.id JOIN state s ON s.code = ts.code - WHERE t.routeFk = ? - AND s.\`order\` < ? - AND priority <(SELECT t.priority + WHERE t.routeFk = ? + AND s.\`order\` < ? + AND priority <(SELECT t.priority FROM ticket t WHERE t.id = ?)` , [ticket.routeFk, orderState.id, ticket.id], myOptions); if (ticketIncorrect?.length > 0) - await sendMail(ctx, ticket.routeFk, ticket.id, ticket.zone().name); + await sendMail(ticket.routeFk, ticket.id, ticket.zone().name); } if (ticket?.address()?.province()?.country()?.code != 'ES' && ticket.$cmrFk) { @@ -189,26 +191,21 @@ module.exports = Self => { throw e; } await models.Ticket.sendCmrEmail(ctx, externalTickets); + + async function sendMail(route, ticket, zoneName) { + const $t = ctx.req.__; + const fullUrl = `${route}`; + await smtp.send({ + to: 'repartos@verdnatura.es', + subject: $t('Incorrect delivery order alert on route', { + route, + zone: zoneName + }), + html: $t('Ticket has been delivered out of order', { + ticket, + fullUrl + }) + }); + } }; - - async function sendMail(ctx, route, ticket, zoneName) { - const $t = ctx.req.__; - const url = await Self.app.models.Url.getUrl(); - const sendTo = 'repartos@verdnatura.es'; - const fullUrl = `${url}route/${route}/summary`; - const emailSubject = $t('Incorrect delivery order alert on route', { - route, - zone: zoneName - }); - const emailBody = $t('Ticket has been delivered out of order', { - ticket, - fullUrl - }); - - await Self.app.models.Mail.create({ - receiver: sendTo, - subject: emailSubject, - body: emailBody - }); - } }; diff --git a/modules/ticket/back/methods/ticket/specs/saveSign.spec.js b/modules/ticket/back/methods/ticket/specs/saveSign.spec.js index 3b426c2cf..092ff95fd 100644 --- a/modules/ticket/back/methods/ticket/specs/saveSign.spec.js +++ b/modules/ticket/back/methods/ticket/specs/saveSign.spec.js @@ -6,7 +6,7 @@ describe('Ticket saveSign()', () => { getLocale: () => { return 'en'; }, - __: () => {}, + __: t => t, accessToken: {userId: 9} } };