#6379 fixDriverRouteEmail #2018

Merged
jorgep merged 7 commits from 6379-fixDriverRouteEmail into dev 2024-02-12 07:46:56 +00:00
1 changed files with 26 additions and 13 deletions
Showing only changes of commit 4075375d6e - Show all commits

View File

@ -9,24 +9,14 @@ module.exports = Self => {
required: true,
description: 'The client id',
http: {source: 'path'}
},
{
arg: 'recipient',
type: 'string',
description: 'The recipient email',
required: true,
},
{
}, {
arg: 'replyTo',
type: 'string',
description: 'The sender email to reply to',
required: false
},
{
}, {
arg: 'recipientId',
type: 'number',
description: 'The recipient id to send to the recipient preferred language',
required: false
}
],
returns: {
@ -39,5 +29,28 @@ module.exports = Self => {
}
});
Self.driverRouteEmail = ctx => Self.sendTemplate(ctx, 'driver-route');
Self.driverRouteEmail = async(ctx, id) => {
const models = Self.app.models;
const {workerFk, agencyMode} = await Self.findById(id, {
fields: ['workerFk', 'agencyModeFk'],
include: {relation: 'agencyMode'}
});
const {reportMail} = agencyMode();
let user;
let account;
if (workerFk) {
user = await models.VnUser.findById(workerFk, {
fields: ['active', 'id'],
include: {relation: 'emailUser'}
});
account = await models.Account.findById(workerFk);
}
if (user?.active && !account) ctx.args.recipient = reportMail;
else if (user?.active && account) ctx.args.recipient = user.emailUser().email;
else // throws an error?
Self.sendTemplate(ctx, 'driver-route');
};
};