feat: refs #7343 delete sending to user
gitea/salix/pipeline/pr-dev This commit looks good Details

This commit is contained in:
Ivan Mas 2025-01-02 18:04:53 +01:00
parent 98b68a2c74
commit 8822fde7fb
1 changed files with 4 additions and 17 deletions

View File

@ -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');
}; };