This commit is contained in:
parent
98b68a2c74
commit
8822fde7fb
|
@ -8,7 +8,7 @@ module.exports = Self => {
|
||||||
arg: 'id',
|
arg: 'id',
|
||||||
type: 'number',
|
type: 'number',
|
||||||
required: true,
|
required: true,
|
||||||
description: 'The client id',
|
description: 'The route id',
|
||||||
http: {source: 'path'}
|
http: {source: 'path'}
|
||||||
}, {
|
}, {
|
||||||
arg: 'replyTo',
|
arg: 'replyTo',
|
||||||
|
@ -31,26 +31,13 @@ module.exports = Self => {
|
||||||
});
|
});
|
||||||
|
|
||||||
Self.driverRouteEmail = async(ctx, id) => {
|
Self.driverRouteEmail = async(ctx, id) => {
|
||||||
const models = Self.app.models;
|
const {agencyMode} = await Self.findById(id, {
|
||||||
const {workerFk, agencyMode} = await Self.findById(id, {
|
fields: ['agencyModeFk'],
|
||||||
fields: ['workerFk', 'agencyModeFk'],
|
|
||||||
include: {relation: 'agencyMode'}
|
include: {relation: 'agencyMode'}
|
||||||
});
|
});
|
||||||
const {reportMail} = 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 = user.emailUser().email;
|
|
||||||
else ctx.args.recipient = reportMail;
|
|
||||||
|
|
||||||
|
ctx.args.recipient = reportMail;
|
||||||
if (!ctx.args.recipient) throw new UserError('An email is necessary');
|
if (!ctx.args.recipient) throw new UserError('An email is necessary');
|
||||||
return Self.sendTemplate(ctx, 'driver-route');
|
return Self.sendTemplate(ctx, 'driver-route');
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue