diff --git a/modules/route/back/methods/route/driverRouteEmail.js b/modules/route/back/methods/route/driverRouteEmail.js index bbac2b0e8..62147db87 100644 --- a/modules/route/back/methods/route/driverRouteEmail.js +++ b/modules/route/back/methods/route/driverRouteEmail.js @@ -39,6 +39,8 @@ module.exports = Self => { const {reportMail} = agencyMode(); let user; let account; + let userEmail; + ctx.args.recipients = reportMail ? reportMail.split(',').map(email => email.trim()) : []; if (workerFk) { user = await models.VnUser.findById(workerFk, { @@ -48,10 +50,17 @@ 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 (userEmail) + ctx.args.recipients.push(userEmail); + + ctx.args.recipients = [...new Set(ctx.args.recipients)]; + + if (!ctx.args.recipients.length) + throw new UserError('An email is necessary'); - if (!ctx.args.recipient) throw new UserError('An email is necessary'); return Self.sendTemplate(ctx, 'driver-route'); }; };