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