fix: refs #6379 get mail

This commit is contained in:
Jorge Penadés 2024-02-09 12:12:10 +01:00
parent e5f2be9f9c
commit 4075375d6e
1 changed files with 26 additions and 13 deletions

View File

@ -9,24 +9,14 @@ module.exports = Self => {
required: true, required: true,
description: 'The client id', description: 'The client id',
http: {source: 'path'} http: {source: 'path'}
}, }, {
{
arg: 'recipient',
type: 'string',
description: 'The recipient email',
required: true,
},
{
arg: 'replyTo', arg: 'replyTo',
type: 'string', type: 'string',
description: 'The sender email to reply to', description: 'The sender email to reply to',
required: false }, {
},
{
arg: 'recipientId', arg: 'recipientId',
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
} }
], ],
returns: { 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');
};
}; };