From 7e5f50e637a8e8f67e2527a1de46a556d1d4db26 Mon Sep 17 00:00:00 2001 From: alexandre Date: Mon, 30 Jan 2023 08:30:39 +0100 Subject: [PATCH] refs #5072 email validation added --- db/changes/230401/00-updateIsToBeMailed.sql | 6 ++++++ loopback/locale/es.json | 3 ++- modules/client/back/models/client.js | 10 ++++++++++ 3 files changed, 18 insertions(+), 1 deletion(-) create mode 100644 db/changes/230401/00-updateIsToBeMailed.sql diff --git a/db/changes/230401/00-updateIsToBeMailed.sql b/db/changes/230401/00-updateIsToBeMailed.sql new file mode 100644 index 000000000..c04090663 --- /dev/null +++ b/db/changes/230401/00-updateIsToBeMailed.sql @@ -0,0 +1,6 @@ +UPDATE vn.client + SET isToBeMailed = FALSE + WHERE + mailAddress is NULL + AND email is NULL + AND isToBeMailed = TRUE; diff --git a/loopback/locale/es.json b/loopback/locale/es.json index d65054f37..1bf6c18f0 100644 --- a/loopback/locale/es.json +++ b/loopback/locale/es.json @@ -259,5 +259,6 @@ "Try again": "Vuelve a intentarlo", "AplicaciĆ³n bloqueada por el usuario 9": "AplicaciĆ³n bloqueada por el usuario 9", "Failed to upload file": "Error al subir archivo", - "The DOCUWARE PDF document does not exists": "The DOCUWARE PDF document does not exists" + "The DOCUWARE PDF document does not exists": "The DOCUWARE PDF document does not exists", + "There is no assigned email for this client": "No hay correo asignado para este cliente" } diff --git a/modules/client/back/models/client.js b/modules/client/back/models/client.js index e07993f79..2d8e7bd27 100644 --- a/modules/client/back/models/client.js +++ b/modules/client/back/models/client.js @@ -141,6 +141,16 @@ module.exports = Self => { done(); } + Self.validateAsync('isToBeMailed', isToBeMailed, { + message: 'There is no assigned email for this client' + }); + + function isToBeMailed(err, done) { + if (this.isToBeMailed == true && !this.email) + err(); + done(); + } + Self.validateAsync('defaultAddressFk', isActive, {message: 'Unable to default a disabled consignee'} );