8032-devToTest_2440 #3009

Merged
alexm merged 262 commits from 8032-devToTest_2440 into test 2024-09-24 09:34:49 +00:00
1 changed files with 17 additions and 3 deletions
Showing only changes of commit c30ecd3760 - Show all commits

View File

@ -39,6 +39,8 @@ module.exports = Self => {
const {reportMail} = agencyMode();
let user;
let account;
let userEmail = null;
let reportEmails = reportMail ? reportMail.split(',').map(email => email.trim()) : [];
if (workerFk) {
user = await models.VnUser.findById(workerFk, {
@ -48,10 +50,22 @@ module.exports = Self => {
account = await models.Account.findById(workerFk);
}
if (user?.active && account) ctx.args.recipient = user.emailUser().email;
else ctx.args.recipient = reportMail;
if (user?.active && account) {
userEmail = user.emailUser().email;
}
if (!ctx.args.recipient) throw new UserError('An email is necessary');
let recipients = reportEmails;
if (userEmail) {
recipients.push(userEmail);
}
recipients = [...new Set(recipients)];
if (recipients.length === 0) {
throw new UserError('An email is necessary');
}
ctx.args.recipients = recipients;
return Self.sendTemplate(ctx, 'driver-route');
};
};