4903-sendMail_refactor #1181
|
@ -332,18 +332,9 @@ module.exports = Self => {
|
||||||
}, myOptions);
|
}, myOptions);
|
||||||
|
|
||||||
const timestamp = started.getTime() / 1000;
|
const timestamp = started.getTime() / 1000;
|
||||||
await models.Mail.create({
|
const url = `${salix.url}worker/${previousWorkerFk}/time-control?timestamp=${timestamp}`;
|
||||||
receiver: previousReceiver,
|
|
||||||
subject: $t('Record of hours week', {
|
|
||||||
week: args.week,
|
|
||||||
year: args.year
|
|
||||||
}),
|
|
||||||
body: `${salix.url}worker/${previousWorkerFk}/time-control?timestamp=${timestamp}`
|
|
||||||
}, myOptions);
|
|
||||||
|
|
||||||
query = `INSERT IGNORE INTO workerTimeControlMail (workerFk, year, week)
|
await models.WorkerTimeControl.weeklyHourRecordEmail(ctx, previousReceiver, args.week, args.year, url);
|
||||||
VALUES (?, ?, ?);`;
|
|
||||||
await Self.rawSql(query, [previousWorkerFk, args.year, args.week], myOptions);
|
|
||||||
|
|
||||||
previousWorkerFk = day.workerFk;
|
previousWorkerFk = day.workerFk;
|
||||||
previousReceiver = day.receiver;
|
previousReceiver = day.receiver;
|
||||||
|
|
|
@ -2,15 +2,12 @@ const models = require('vn-loopback/server/server').models;
|
||||||
|
|
||||||
describe('workerTimeControl sendMail()', () => {
|
describe('workerTimeControl sendMail()', () => {
|
||||||
const workerId = 18;
|
const workerId = 18;
|
||||||
const ctx = {
|
const activeCtx = {
|
||||||
req: {
|
getLocale: () => {
|
||||||
__: value => {
|
return 'en';
|
||||||
return value;
|
}
|
||||||
}
|
|
||||||
},
|
|
||||||
args: {}
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
const ctx = {req: activeCtx, args: {}};
|
||||||
|
|
||||||
it('should fill time control of a worker without records in Journey and with rest', async() => {
|
it('should fill time control of a worker without records in Journey and with rest', async() => {
|
||||||
const tx = await models.WorkerTimeControl.beginTransaction({});
|
const tx = await models.WorkerTimeControl.beginTransaction({});
|
||||||
|
|
|
@ -0,0 +1,53 @@
|
||||||
|
const {Email} = require('vn-print');
|
||||||
|
|
||||||
|
module.exports = Self => {
|
||||||
|
Self.remoteMethodCtx('weeklyHourRecordEmail', {
|
||||||
|
description: 'Sends the buyer waste email',
|
||||||
|
accessType: 'WRITE',
|
||||||
|
accepts: [
|
||||||
|
{
|
||||||
|
arg: 'recipient',
|
||||||
|
type: 'string',
|
||||||
|
description: 'The recipient email',
|
||||||
|
required: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
arg: 'week',
|
||||||
|
type: 'number',
|
||||||
|
required: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
arg: 'year',
|
||||||
|
type: 'number',
|
||||||
|
required: true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
arg: 'url',
|
||||||
|
type: 'string',
|
||||||
|
required: true
|
||||||
|
}
|
||||||
|
],
|
||||||
|
returns: {
|
||||||
|
type: ['object'],
|
||||||
|
root: true
|
||||||
|
},
|
||||||
|
http: {
|
||||||
|
path: '/weekly-hour-hecord-email',
|
||||||
|
verb: 'POST'
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
Self.weeklyHourRecordEmail = async(ctx, recipient, week, year, url) => {
|
||||||
|
const params = {
|
||||||
|
recipient: recipient,
|
||||||
|
lang: ctx.req.getLocale(),
|
||||||
|
week: week,
|
||||||
|
year: year,
|
||||||
|
url: url
|
||||||
|
};
|
||||||
|
|
||||||
|
const email = new Email('weekly-hour-record', params);
|
||||||
|
|
||||||
|
return email.send();
|
||||||
|
};
|
||||||
|
};
|
|
@ -7,6 +7,7 @@ module.exports = Self => {
|
||||||
require('../methods/worker-time-control/updateTimeEntry')(Self);
|
require('../methods/worker-time-control/updateTimeEntry')(Self);
|
||||||
require('../methods/worker-time-control/sendMail')(Self);
|
require('../methods/worker-time-control/sendMail')(Self);
|
||||||
require('../methods/worker-time-control/updateWorkerTimeControlMail')(Self);
|
require('../methods/worker-time-control/updateWorkerTimeControlMail')(Self);
|
||||||
|
require('../methods/worker-time-control/weeklyHourRecordEmail')(Self);
|
||||||
|
|
||||||
Self.rewriteDbError(function(err) {
|
Self.rewriteDbError(function(err) {
|
||||||
if (err.code === 'ER_DUP_ENTRY')
|
if (err.code === 'ER_DUP_ENTRY')
|
||||||
|
|
|
@ -0,0 +1,12 @@
|
||||||
|
const Stylesheet = require(`vn-print/core/stylesheet`);
|
||||||
|
|
||||||
|
const path = require('path');
|
||||||
|
const vnPrintPath = path.resolve('print');
|
||||||
|
|
||||||
|
module.exports = new Stylesheet([
|
||||||
|
`${vnPrintPath}/common/css/spacing.css`,
|
||||||
|
`${vnPrintPath}/common/css/misc.css`,
|
||||||
|
`${vnPrintPath}/common/css/layout.css`,
|
||||||
|
`${vnPrintPath}/common/css/email.css`])
|
||||||
|
.mergeStyles();
|
||||||
|
|
|
@ -0,0 +1,6 @@
|
||||||
|
subject: Weekly time log
|
||||||
|
title: Record of hours week {0} year {1}
|
||||||
|
dear: Dear worker
|
||||||
|
description: Access the following link:<br/><br/>
|
||||||
|
{0} <br/><br/>
|
||||||
|
Click 'SATISFIED' if you agree with the hours worked. Otherwise, press 'NOT SATISFIED', detailing the cause of the disagreement.
|
|
@ -0,0 +1,6 @@
|
||||||
|
subject: Registro de horas semanal
|
||||||
|
title: Registro de horas semana {0} año {1}
|
||||||
|
dear: Estimado trabajador
|
||||||
|
description: Acceda al siguiente enlace:<br/><br/>
|
||||||
|
{0} <br/><br/>
|
||||||
|
Pulse 'CONFORME' si esta de acuerdo con las horas trabajadas. En caso contrario pulse 'NO CONFORME', detallando la causa de la disconformidad.
|
|
@ -0,0 +1,9 @@
|
||||||
|
<email-body v-bind="$props">
|
||||||
|
<div class="grid-row">
|
||||||
|
<div class="grid-block vn-pa-ml">
|
||||||
|
<h1>{{ $t('title', [week, year]) }}</h1>
|
||||||
|
<p>{{$t('dear')}},</p>
|
||||||
|
<p v-html="$t('description', [url])"></p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</email-body>
|
|
@ -0,0 +1,23 @@
|
||||||
|
const Component = require(`vn-print/core/component`);
|
||||||
|
const emailBody = new Component('email-body');
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
name: 'weekly-hour-record',
|
||||||
|
components: {
|
||||||
|
'email-body': emailBody.build()
|
||||||
|
},
|
||||||
|
props: {
|
||||||
|
week: {
|
||||||
|
type: Number,
|
||||||
|
required: true
|
||||||
|
},
|
||||||
|
year: {
|
||||||
|
type: Number,
|
||||||
|
required: true
|
||||||
|
},
|
||||||
|
url: {
|
||||||
|
type: String,
|
||||||
|
required: true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
Loading…
Reference in New Issue