From 465955d0c518437733f48ca1b0ef169d33f13386 Mon Sep 17 00:00:00 2001 From: joan Date: Wed, 7 Apr 2021 13:09:53 +0200 Subject: [PATCH 1/3] 2483 - Added replyTo param when sending an email to client --- loopback/locale/en.json | 2 +- loopback/locale/es.json | 2 +- modules/client/back/models/client.js | 27 ++++++++++--------- modules/client/front/sample/create/index.html | 7 +++++ modules/client/front/sample/create/index.js | 15 ++++++++++- 5 files changed, 38 insertions(+), 15 deletions(-) diff --git a/loopback/locale/en.json b/loopback/locale/en.json index f9fe404889..1e06078134 100644 --- a/loopback/locale/en.json +++ b/loopback/locale/en.json @@ -59,7 +59,7 @@ "Swift / BIC can't be empty": "Swift / BIC can't be empty", "Bought units from buy request": "Bought {{quantity}} units of {{concept}} [{{itemId}}]({{{urlItem}}}) for the ticket id [{{ticketId}}]({{{url}}})", "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}}})", + "Changed client 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}}})", "Claim will be picked": "The product from the claim [({{claimId}})]({{{claimUrl}}}) from the client *{{clientName}}* will be picked", "Claim state has changed to incomplete": "The state of the claim [({{claimId}})]({{{claimUrl}}}) from client *{{clientName}}* has changed to *incomplete*", diff --git a/loopback/locale/es.json b/loopback/locale/es.json index b113655776..cef64b43ab 100644 --- a/loopback/locale/es.json +++ b/loopback/locale/es.json @@ -123,7 +123,7 @@ "Incoterms is required for a non UEE member": "El incoterms es requerido para los clientes extracomunitarios", "Bought units from buy request": "Se ha comprado {{quantity}} unidades de {{concept}} [{{itemId}}]({{{urlItem}}}) para el ticket id [{{ticketId}}]({{{url}}})", "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}}})", + "Changed client 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}}})", "Claim will be picked": "Se recogerá el género de la reclamación [({{claimId}})]({{{claimUrl}}}) del cliente *{{clientName}}*", "Claim state has changed to incomplete": "Se ha cambiado el estado de la reclamación [({{claimId}})]({{{claimUrl}}}) del cliente *{{clientName}}* a *incompleta*", diff --git a/modules/client/back/models/client.js b/modules/client/back/models/client.js index e1de363b22..035074210b 100644 --- a/modules/client/back/models/client.js +++ b/modules/client/back/models/client.js @@ -253,25 +253,28 @@ module.exports = Self => { const salesPersonId = instance.salesPersonFk; if (salesPersonId) { + // Send email to client + if (instance.email) { + const worker = await models.EmailUser.findById(salesPersonId); + const params = { + authorization: authorization, + recipientId: instance.id, + recipient: instance.email, + replyTo: worker.email + }; + await got.get(`${origin}/api/email/payment-update`, { + query: params + }); + } + const fullUrl = `${origin}/#!/client/${instance.id}/billing-data`; - const message = $t('MESSAGE_CHANGED_PAYMETHOD', { + const message = $t('Changed client paymethod', { clientId: instance.id, clientName: instance.name, url: fullUrl }); await models.Chat.sendCheckingPresence(httpCtx, salesPersonId, message); } - - // Send email to client - if (!instance.email) return; - const params = { - authorization: authorization, - recipientId: instance.id, - recipient: instance.email - }; - await got.get(`${origin}/api/email/payment-update`, { - query: params - }); } const workerIdBefore = oldInstance.salesPersonFk; diff --git a/modules/client/front/sample/create/index.html b/modules/client/front/sample/create/index.html index f941e885ad..e6733a6567 100644 --- a/modules/client/front/sample/create/index.html +++ b/modules/client/front/sample/create/index.html @@ -32,6 +32,13 @@ info="Its only used when sample is sent"> + + + + { + const [worker] = res && res.data; + this.clientSample.replyTo = worker.email; + }); + } } + Controller.$inject = ['$element', '$scope']; ngModule.vnComponent('vnClientSampleCreate', { From 418d7a2d12aaa58f97f43c575b30eb26de652fc7 Mon Sep 17 00:00:00 2001 From: joan Date: Wed, 7 Apr 2021 14:14:31 +0200 Subject: [PATCH 2/3] Updated unit test --- modules/client/front/sample/create/index.js | 6 +++--- modules/client/front/sample/create/index.spec.js | 12 ++++++++++++ 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/modules/client/front/sample/create/index.js b/modules/client/front/sample/create/index.js index c2ac99ae55..0eaeddc20b 100644 --- a/modules/client/front/sample/create/index.js +++ b/modules/client/front/sample/create/index.js @@ -9,8 +9,6 @@ class Controller extends Section { clientFk: this.$params.id, companyId: this.vnConfig.companyFk }; - - this.getWorkerEmail(); } get client() { @@ -20,8 +18,10 @@ class Controller extends Section { set client(value) { this._client = value; - if (value) + if (value) { this.clientSample.recipient = value.email; + this.getWorkerEmail(); + } } get companyId() { diff --git a/modules/client/front/sample/create/index.spec.js b/modules/client/front/sample/create/index.spec.js index 40fa237b68..37d322b5fd 100644 --- a/modules/client/front/sample/create/index.spec.js +++ b/modules/client/front/sample/create/index.spec.js @@ -179,5 +179,17 @@ describe('Client', () => { expect(controller.$state.go).toHaveBeenCalledWith('client.card.sample.index'); }); }); + + describe('getWorkerEmail()', () => { + it(`should perform a query and then set the replyTo property to the clientSample object`, () => { + const expectedEmail = 'batman@arkhamcity.com'; + const serializedParams = $httpParamSerializer({filter: {where: {}}}); + $httpBackend.expect('GET', `EmailUsers?${serializedParams}`).respond([{email: expectedEmail}]); + controller.getWorkerEmail(); + $httpBackend.flush(); + + expect(controller.clientSample.replyTo).toEqual(expectedEmail); + }); + }); }); }); From 7033ec2c11fe5d69a8210a46f45d83b9be05d8b4 Mon Sep 17 00:00:00 2001 From: joan Date: Tue, 13 Apr 2021 10:39:42 +0200 Subject: [PATCH 3/3] Added missing translations --- modules/client/front/sample/create/locale/es.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/modules/client/front/sample/create/locale/es.yml b/modules/client/front/sample/create/locale/es.yml index 6828e3e489..a534e05d49 100644 --- a/modules/client/front/sample/create/locale/es.yml +++ b/modules/client/front/sample/create/locale/es.yml @@ -2,4 +2,6 @@ Choose a sample: Selecciona una plantilla Choose a company: Selecciona una empresa Email cannot be blank: Debes introducir un email Recipient: Destinatario -Its only used when sample is sent: Se utiliza únicamente cuando se envía la plantilla \ No newline at end of file +Its only used when sample is sent: Se utiliza únicamente cuando se envía la plantilla +Reply to: Responder a +To who should the recipient reply?: ¿A quíen debería responder el destinatario? \ No newline at end of file