From c30ecd3760c873a3df9eb6616cc4a330570e4b1f Mon Sep 17 00:00:00 2001 From: ivanm Date: Thu, 19 Sep 2024 12:26:06 +0200 Subject: [PATCH 1/2] feat: refs #7343 Modify driverRouteEmail.js --- .../back/methods/route/driverRouteEmail.js | 20 ++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/modules/route/back/methods/route/driverRouteEmail.js b/modules/route/back/methods/route/driverRouteEmail.js index bbac2b0e8..467528989 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 = 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'); }; }; -- 2.40.1 From c82c9395a4e9d0ab883dd7830804db3402c4fe82 Mon Sep 17 00:00:00 2001 From: ivanm Date: Thu, 19 Sep 2024 12:49:45 +0200 Subject: [PATCH 2/2] feat: refs #7343 Requested changes --- .../back/methods/route/driverRouteEmail.js | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/modules/route/back/methods/route/driverRouteEmail.js b/modules/route/back/methods/route/driverRouteEmail.js index 467528989..62147db87 100644 --- a/modules/route/back/methods/route/driverRouteEmail.js +++ b/modules/route/back/methods/route/driverRouteEmail.js @@ -39,8 +39,8 @@ module.exports = Self => { const {reportMail} = agencyMode(); let user; let account; - let userEmail = null; - let reportEmails = reportMail ? reportMail.split(',').map(email => email.trim()) : []; + let userEmail; + ctx.args.recipients = reportMail ? reportMail.split(',').map(email => email.trim()) : []; if (workerFk) { user = await models.VnUser.findById(workerFk, { @@ -50,22 +50,17 @@ module.exports = Self => { account = await models.Account.findById(workerFk); } - if (user?.active && account) { + if (user?.active && account) userEmail = user.emailUser().email; - } - let recipients = reportEmails; - if (userEmail) { - recipients.push(userEmail); - } + if (userEmail) + ctx.args.recipients.push(userEmail); - recipients = [...new Set(recipients)]; + ctx.args.recipients = [...new Set(ctx.args.recipients)]; - if (recipients.length === 0) { + if (!ctx.args.recipients.length) throw new UserError('An email is necessary'); - } - ctx.args.recipients = recipients; return Self.sendTemplate(ctx, 'driver-route'); }; }; -- 2.40.1