refactor(claim_claimPickupEmail): use text template and external form
gitea/salix/pipeline/head There was a failure building this commit Details

This commit is contained in:
Alex Moreno 2022-10-17 11:22:27 +02:00
parent 991893837c
commit 79b970286c
9 changed files with 64 additions and 12 deletions

View File

@ -2,7 +2,7 @@
import selectors from '../../helpers/selectors.js'; import selectors from '../../helpers/selectors.js';
import getBrowser from '../../helpers/puppeteer'; import getBrowser from '../../helpers/puppeteer';
describe('Claim summary path', () => { fdescribe('Claim summary path', () => {
let browser; let browser;
let page; let page;
const claimId = '4'; const claimId = '4';

View File

@ -133,5 +133,6 @@
"Descanso semanal 36h. / 72h.": "Weekly rest 36h. / 72h.", "Descanso semanal 36h. / 72h.": "Weekly rest 36h. / 72h.",
"Password does not meet requirements": "Password does not meet requirements", "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", "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" "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}}*"
}

View File

@ -235,5 +235,6 @@
"Dirección incorrecta": "Dirección incorrecta", "Dirección incorrecta": "Dirección incorrecta",
"Modifiable user details only by an administrator": "Detalles de usuario modificables solo por un administrador", "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", "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" "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}}*"
}

View File

@ -29,6 +29,24 @@ module.exports = Self => {
type: 'number', type: 'number',
description: 'The recipient id to send to the recipient preferred language', description: 'The recipient id to send to the recipient preferred language',
required: false 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: { returns: {
@ -42,6 +60,11 @@ module.exports = Self => {
}); });
Self.claimPickupEmail = async ctx => { 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 args = Object.assign({}, ctx.args);
const params = { const params = {
recipient: args.recipient, recipient: args.recipient,
@ -52,6 +75,23 @@ module.exports = Self => {
for (const param in args) for (const param in args)
params[param] = args[param]; 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); const email = new Email('claim-pickup-order', params);
return email.send(); return email.send();

View File

@ -19,7 +19,10 @@ class Controller extends Descriptor {
sendPickupOrder() { sendPickupOrder() {
return this.vnEmail.send(`Claims/${this.claim.id}/claim-pickup-email`, { return this.vnEmail.send(`Claims/${this.claim.id}/claim-pickup-email`, {
recipient: this.claim.client.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
}); });
} }

View File

@ -7,7 +7,12 @@ describe('Item Component vnClaimDescriptor', () => {
const claim = { const claim = {
id: 2, id: 2,
clientFk: 1101, clientFk: 1101,
client: {email: 'client@email'} client: {
email: 'client@email',
name: 'clientName',
salesPersonFk: 18
},
ticket: {id: 2}
}; };
beforeEach(ngModule('claim')); beforeEach(ngModule('claim'));
@ -40,7 +45,10 @@ describe('Item Component vnClaimDescriptor', () => {
const params = { const params = {
recipient: claim.client.email, recipient: claim.client.email,
recipientId: claim.clientFk recipientId: claim.clientFk,
clientName: claim.client.name,
ticketId: claim.ticket.id,
salesPersonId: claim.client.salesPersonFk
}; };
controller.sendPickupOrder(); controller.sendPickupOrder();

View File

@ -23,7 +23,7 @@
<!-- Block --> <!-- Block -->
<div class="grid-row"> <div class="grid-row">
<div class="grid-block vn-pa-ml"> <div class="grid-block vn-pa-ml">
<h1>{{ $t('title', [claimId]) }}</h1> <h1>{{ $t('title', [id]) }}</h1>
<p>{{ $t('description.dear') }},</p> <p>{{ $t('description.dear') }},</p>
<p v-html="instructions"></p> <p v-html="instructions"></p>
<p>{{ $t('description.conclusion') }}</p> <p>{{ $t('description.conclusion') }}</p>

View File

@ -9,7 +9,7 @@ module.exports = {
'email-footer': emailFooter.build() 'email-footer': emailFooter.build()
}, },
created() { created() {
this.instructions = this.$t('description.instructions', [this.claimId, this.ticketId]); this.instructions = this.$t('description.instructions', [this.id, this.ticketId]);
}, },
data() { data() {
return { return {

View File

@ -7,7 +7,6 @@ module.exports = {
async serverPrefetch() { async serverPrefetch() {
this.client = await this.fetchClient(this.id); this.client = await this.fetchClient(this.id);
this.sales = await this.fetchSales(this.id); this.sales = await this.fetchSales(this.id);
this.claimConfig = await this.fetchClaimConfig();
if (!this.client) if (!this.client)
throw new Error('Something went wrong'); throw new Error('Something went wrong');
@ -25,7 +24,7 @@ module.exports = {
}, },
fetchSales(id) { fetchSales(id) {
return this.rawSqlFromDef('sales', [id]); return this.rawSqlFromDef('sales', [id]);
}, }
}, },
components: { components: {
'report-header': reportHeader.build(), 'report-header': reportHeader.build(),