From e0de498f659733ec747b5cc0ac7cd865b55aac1d Mon Sep 17 00:00:00 2001 From: jorgep Date: Fri, 9 Feb 2024 13:04:27 +0100 Subject: [PATCH] fix: refs #6379 add Error & locale --- loopback/locale/en.json | 3 ++- loopback/locale/es.json | 3 ++- modules/route/back/methods/route/driverRouteEmail.js | 9 +++++---- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/loopback/locale/en.json b/loopback/locale/en.json index 419775d1b..33db02516 100644 --- a/loopback/locale/en.json +++ b/loopback/locale/en.json @@ -206,5 +206,6 @@ "Incorrect pin": "Incorrect pin.", "The notification subscription of this worker cant be modified": "The notification subscription of this worker cant be modified", "Name should be uppercase": "Name should be uppercase", - "You cannot update these fields": "You cannot update these fields" + "You cannot update these fields": "You cannot update these fields", + "CountryFK cannot be empty": "CountryFK cannot be empty" } \ No newline at end of file diff --git a/loopback/locale/es.json b/loopback/locale/es.json index dac839085..42215edd6 100644 --- a/loopback/locale/es.json +++ b/loopback/locale/es.json @@ -340,5 +340,6 @@ "Name should be uppercase": "El nombre debe ir en mayúscula", "Bank entity must be specified": "La entidad bancaria es obligatoria", "An email is necessary": "Es necesario un email", - "You cannot update these fields": "No puedes actualizar estos campos" + "You cannot update these fields": "No puedes actualizar estos campos", + "CountryFK cannot be empty": "CountryFK cannot be empty" } \ No newline at end of file diff --git a/modules/route/back/methods/route/driverRouteEmail.js b/modules/route/back/methods/route/driverRouteEmail.js index e4fd17b5f..35814de3c 100644 --- a/modules/route/back/methods/route/driverRouteEmail.js +++ b/modules/route/back/methods/route/driverRouteEmail.js @@ -1,3 +1,4 @@ +const UserError = require('vn-loopback/util/user-error'); module.exports = Self => { Self.remoteMethodCtx('driverRouteEmail', { description: 'Sends the driver route email with an attached PDF', @@ -47,10 +48,10 @@ module.exports = Self => { account = await models.Account.findById(workerFk); } - if (user?.active && !account) ctx.args.recipient = reportMail; - else if (user?.active && account) ctx.args.recipient = user.emailUser().email; - else // throws an error? + if (user?.active && account) ctx.args.recipient = user.emailUser().email; + else ctx.args.recipient = reportMail; - Self.sendTemplate(ctx, 'driver-route'); + if (!ctx.args.recipient) throw new UserError('An email is necessary'); + Self.sendTemplate(ctx, 'driver-route'); }; };