From 79b970286c1b382a8b90a8969e55a1a5a11445d8 Mon Sep 17 00:00:00 2001 From: alexm Date: Mon, 17 Oct 2022 11:22:27 +0200 Subject: [PATCH] refactor(claim_claimPickupEmail): use text template and external form --- e2e/paths/06-claim/05_summary.spec.js | 2 +- loopback/locale/en.json | 5 ++- loopback/locale/es.json | 5 ++- .../back/methods/claim/claimPickupEmail.js | 40 +++++++++++++++++++ modules/claim/front/descriptor/index.js | 5 ++- modules/claim/front/descriptor/index.spec.js | 12 +++++- .../claim-pickup-order.html | 2 +- .../claim-pickup-order/claim-pickup-order.js | 2 +- .../claim-pickup-order/claim-pickup-order.js | 3 +- 9 files changed, 64 insertions(+), 12 deletions(-) diff --git a/e2e/paths/06-claim/05_summary.spec.js b/e2e/paths/06-claim/05_summary.spec.js index 00b021f88..05d18a2c3 100644 --- a/e2e/paths/06-claim/05_summary.spec.js +++ b/e2e/paths/06-claim/05_summary.spec.js @@ -2,7 +2,7 @@ import selectors from '../../helpers/selectors.js'; import getBrowser from '../../helpers/puppeteer'; -describe('Claim summary path', () => { +fdescribe('Claim summary path', () => { let browser; let page; const claimId = '4'; diff --git a/loopback/locale/en.json b/loopback/locale/en.json index e5a0fae32..e9311800e 100644 --- a/loopback/locale/en.json +++ b/loopback/locale/en.json @@ -133,5 +133,6 @@ "Descanso semanal 36h. / 72h.": "Weekly rest 36h. / 72h.", "Password does not meet requirements": "Password does not meet requirements", "You don't have privileges to change the zone": "You don't have privileges to change the zone or for these parameters there are more than one shipping options, talk to agencies", - "Not enough privileges to edit a client": "Not enough privileges to edit a client" -} \ No newline at end of file + "Not enough privileges to edit a client": "Not enough privileges to edit a client", + "Claim pickup order sent": "Claim pickup order sent [({{claimId}})]({{{claimUrl}}}) to client *{{clientName}}*" +} diff --git a/loopback/locale/es.json b/loopback/locale/es.json index 67370b343..8caf76836 100644 --- a/loopback/locale/es.json +++ b/loopback/locale/es.json @@ -235,5 +235,6 @@ "Dirección incorrecta": "Dirección incorrecta", "Modifiable user details only by an administrator": "Detalles de usuario modificables solo por un administrador", "Modifiable password only via recovery or by an administrator": "Contraseña modificable solo a través de la recuperación o por un administrador", - "Not enough privileges to edit a client": "No tienes suficientes privilegios para editar un cliente" -} \ No newline at end of file + "Not enough privileges to edit a client": "No tienes suficientes privilegios para editar un cliente", + "Claim pickup order sent": "Reclamación Orden de recogida enviada [({{claimId}})]({{{claimUrl}}}) al cliente *{{clientName}}*" +} diff --git a/modules/claim/back/methods/claim/claimPickupEmail.js b/modules/claim/back/methods/claim/claimPickupEmail.js index 4d64cc66e..4c9b86502 100644 --- a/modules/claim/back/methods/claim/claimPickupEmail.js +++ b/modules/claim/back/methods/claim/claimPickupEmail.js @@ -29,6 +29,24 @@ module.exports = Self => { type: 'number', description: 'The recipient id to send to the recipient preferred language', required: false + }, + { + arg: 'ticketId', + type: 'number', + description: 'The ticket id', + required: true + }, + { + arg: 'salesPersonId', + type: 'number', + description: 'The salesPerson id', + required: false + }, + { + arg: 'clientName', + type: 'string', + description: 'The client name', + required: true } ], returns: { @@ -42,6 +60,11 @@ module.exports = Self => { }); Self.claimPickupEmail = async ctx => { + const models = Self.app.models; + const userId = ctx.req.accessToken.userId; + const $t = ctx.req.__; // $translate + const origin = ctx.req.headers.origin; + const args = Object.assign({}, ctx.args); const params = { recipient: args.recipient, @@ -52,6 +75,23 @@ module.exports = Self => { for (const param in args) params[param] = args[param]; + const message = $t('Claim pickup order sent', { + claimId: args.id, + clientName: args.clientName, + claimUrl: `${origin}/#!/claim/${args.id}/summary`, + }); + + if (args.salesPersonId) + await models.Chat.sendCheckingPresence(ctx, args.salesPersonId, message); + + await models.ClaimLog.create({ + originFk: args.id, + userFk: userId, + action: 'insert', + description: 'Claim-pickup-order sent', + changedModel: 'Mail' + }); + const email = new Email('claim-pickup-order', params); return email.send(); diff --git a/modules/claim/front/descriptor/index.js b/modules/claim/front/descriptor/index.js index 0dddadbe1..b36fae321 100644 --- a/modules/claim/front/descriptor/index.js +++ b/modules/claim/front/descriptor/index.js @@ -19,7 +19,10 @@ class Controller extends Descriptor { sendPickupOrder() { return this.vnEmail.send(`Claims/${this.claim.id}/claim-pickup-email`, { recipient: this.claim.client.email, - recipientId: this.claim.clientFk + recipientId: this.claim.clientFk, + clientName: this.claim.client.name, + ticketId: this.claim.ticket.id, + salesPersonId: this.claim.client.salesPersonFk }); } diff --git a/modules/claim/front/descriptor/index.spec.js b/modules/claim/front/descriptor/index.spec.js index e6785d3d8..18ccdaff5 100644 --- a/modules/claim/front/descriptor/index.spec.js +++ b/modules/claim/front/descriptor/index.spec.js @@ -7,7 +7,12 @@ describe('Item Component vnClaimDescriptor', () => { const claim = { id: 2, clientFk: 1101, - client: {email: 'client@email'} + client: { + email: 'client@email', + name: 'clientName', + salesPersonFk: 18 + }, + ticket: {id: 2} }; beforeEach(ngModule('claim')); @@ -40,7 +45,10 @@ describe('Item Component vnClaimDescriptor', () => { const params = { recipient: claim.client.email, - recipientId: claim.clientFk + recipientId: claim.clientFk, + clientName: claim.client.name, + ticketId: claim.ticket.id, + salesPersonId: claim.client.salesPersonFk }; controller.sendPickupOrder(); diff --git a/print/templates/email/claim-pickup-order/claim-pickup-order.html b/print/templates/email/claim-pickup-order/claim-pickup-order.html index e6e74ed93..32606bd7b 100644 --- a/print/templates/email/claim-pickup-order/claim-pickup-order.html +++ b/print/templates/email/claim-pickup-order/claim-pickup-order.html @@ -23,7 +23,7 @@
-

{{ $t('title', [claimId]) }}

+

{{ $t('title', [id]) }}

{{ $t('description.dear') }},

{{ $t('description.conclusion') }}

diff --git a/print/templates/email/claim-pickup-order/claim-pickup-order.js b/print/templates/email/claim-pickup-order/claim-pickup-order.js index 74ee9408d..51db21cb5 100755 --- a/print/templates/email/claim-pickup-order/claim-pickup-order.js +++ b/print/templates/email/claim-pickup-order/claim-pickup-order.js @@ -9,7 +9,7 @@ module.exports = { 'email-footer': emailFooter.build() }, created() { - this.instructions = this.$t('description.instructions', [this.claimId, this.ticketId]); + this.instructions = this.$t('description.instructions', [this.id, this.ticketId]); }, data() { return { diff --git a/print/templates/reports/claim-pickup-order/claim-pickup-order.js b/print/templates/reports/claim-pickup-order/claim-pickup-order.js index 022042845..c2c11cb88 100755 --- a/print/templates/reports/claim-pickup-order/claim-pickup-order.js +++ b/print/templates/reports/claim-pickup-order/claim-pickup-order.js @@ -7,7 +7,6 @@ module.exports = { async serverPrefetch() { this.client = await this.fetchClient(this.id); this.sales = await this.fetchSales(this.id); - this.claimConfig = await this.fetchClaimConfig(); if (!this.client) throw new Error('Something went wrong'); @@ -25,7 +24,7 @@ module.exports = { }, fetchSales(id) { return this.rawSqlFromDef('sales', [id]); - }, + } }, components: { 'report-header': reportHeader.build(),