#6379 fixDriverRouteEmail #2018
|
@ -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');
|
||||
};
|
||||
jorgep marked this conversation as resolved
Outdated
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue
i aci igual val la pena posar un await