refs #5410 creada ruta de back para enviar emails
gitea/salix/pipeline/head This commit looks good Details

This commit is contained in:
Vicent Llopis 2023-04-04 14:09:55 +02:00
parent c89f95a33e
commit 3630c7d398
6 changed files with 64 additions and 23 deletions

View File

@ -268,9 +268,11 @@
"Exists an invoice with a previous date": "Existe una factura con fecha anterior",
"Invoice date can't be less than max date": "La fecha de factura no puede ser inferior a la fecha límite",
"Warehouse inventory not set": "El almacén inventario no está establecido",
"This locker has already been assigned": "Esta taquilla ya ha sido asignada",
"This locker has already been assigned": "Esta taquilla ya ha sido asignada",
"Tickets with associated refunds": "No se pueden borrar tickets con abonos asociados. Este ticket está asociado al abono Nº {{id}}",
"Not exist this branch": "La rama no existe",
"This ticket cannot be signed because it has not been boxed": "Este ticket no puede firmarse porque no ha sido encajado",
"Insert a date range": "Inserte un rango de fechas"
"This ticket cannot be signed because it has not been boxed": "Este ticket no puede firmarse porque no ha sido encajado",
"Insert a date range": "Inserte un rango de fechas",
"Added observation": "{{user}} añadió esta observacion: {{text}}",
"Comment added to client": "Observación añadida al cliente {{clientFk}}"
}

View File

@ -0,0 +1,52 @@
module.exports = Self => {
Self.remoteMethodCtx('observationEmail', {
description: 'Send an email with the observation',
accessType: 'WRITE',
accepts: [
{
arg: 'defaulters',
type: ['object'],
required: true,
description: 'The defaulters to send the email'
},
{
arg: 'observation',
type: 'string',
required: true,
description: 'The observation'
}],
returns: {
arg: 'observationEmail'
},
http: {
path: `/observationEmail`,
verb: 'POST'
}
});
Self.observationEmail = async(ctx, defaulters, observation, options) => {
const models = Self.app.models;
const $t = ctx.req.__; // $translate
const myOptions = {};
const userId = ctx.req.accessToken.userId;
if (typeof options == 'object')
Object.assign(myOptions, options);
for (const defaulter of defaulters) {
const user = await models.Account.findById(userId, {fields: ['name']}, myOptions);
const body = $t('Added observation', {
user: user.name,
text: observation
});
await models.Mail.create({
subject: $t('Comment added to client', {clientFk: defaulter.clientFk}),
body: body,
receiver: `${defaulter.salesPersonName}@verdnatura.es`,
replyTo: `${user.name}@verdnatura.es`
}, myOptions);
}
};
};

View File

@ -1,3 +1,4 @@
module.exports = Self => {
require('../methods/defaulter/filter')(Self);
require('../methods/defaulter/observationEmail')(Self);
};

View File

@ -130,22 +130,11 @@ export default class Controller extends Section {
}
sendMail() {
const params = [];
for (let defaulter of this.checked) {
const body = this.$t('Added observation', {
salesPersonName: defaulter.salesPersonName,
text: this.defaulter.observation
});
params.push({
subject: this.$t('Comment added to client', {clientFk: defaulter.clientFk}),
body: body,
receiver: `${defaulter.salesPersonName}@verdnatura.es`,
replyTo: `${window.localStorage.lastUser}@verdnatura.es`
});
}
this.$http.post(`Mails`, params);
const params = {
defaulters: this.checked,
observation: this.defaulter.observation
};
this.$http.post(`Defaulters/observationEmail`, params);
}
exprBuilder(param, value) {

View File

@ -80,12 +80,11 @@ describe('client defaulter', () => {
controller.defaulter = {observation: 'My new observation'};
const params = [{text: controller.defaulter.observation, clientFk: data[1].clientFk}];
const mailParams = [{subject: 'Comment added to client', body: 'Added observation', receiver: 'undefined@verdnatura.es', replyTo: 'undefined@verdnatura.es'}];
jest.spyOn(controller.vnApp, 'showSuccess');
$httpBackend.expect('GET', `Defaulters/filter`).respond(200);
$httpBackend.expect('POST', `ClientObservations`, params).respond(200, params);
$httpBackend.expect('POST', `Mails`, mailParams).respond(200);
$httpBackend.expect('POST', `Defaulters/observationEmail`).respond(200);
controller.onResponse();
$httpBackend.flush();

View File

@ -7,7 +7,5 @@ L. O. Date: Fecha Ú. O.
Last observation date: Fecha última observación
Search client: Buscar clientes
Worker who made the last observation: Trabajador que ha realizado la última observación
Added observation: '{{salesPersonName}} añadió esta observacion: {{text}}'
Comment added to client: Observación añadida al cliente {{clientFk}}
Email sended!: Email enviado!
Observation saved!: Observación añadida!