From 4e11e46fff7a0c78b772832e1702ba3e96189449 Mon Sep 17 00:00:00 2001 From: pablone Date: Thu, 25 Apr 2024 12:40:54 +0200 Subject: [PATCH] feat: refs #4988 capture error on duplicate --- back/models/agency-workCenter.js | 8 ++++++++ db/dump/fixtures.before.sql | 3 +++ loopback/locale/en.json | 4 +++- loopback/locale/es.json | 3 ++- 4 files changed, 16 insertions(+), 2 deletions(-) create mode 100644 back/models/agency-workCenter.js diff --git a/back/models/agency-workCenter.js b/back/models/agency-workCenter.js new file mode 100644 index 000000000..3220999e9 --- /dev/null +++ b/back/models/agency-workCenter.js @@ -0,0 +1,8 @@ +let UserError = require('vn-loopback/util/user-error'); +module.exports = Self => { + Self.rewriteDbError(function(err) { + if (err.code === 'ER_DUP_ENTRY') + return new UserError(`This workCenter is already assigned to this agency`); + return err; + }); +}; diff --git a/db/dump/fixtures.before.sql b/db/dump/fixtures.before.sql index ff58af2e2..ee115751e 100644 --- a/db/dump/fixtures.before.sql +++ b/db/dump/fixtures.before.sql @@ -3787,3 +3787,6 @@ INSERT INTO `vn`.`accountReconciliationConfig`(currencyFk, warehouseFk) INSERT INTO vn.workerTeam(id, team, workerFk) VALUES (8, 1, 19); + +INSERT INTO vn.workCenter (id, name, payrollCenterFk, counter, warehouseFk, street, geoFk, deliveryManAdjustment) + VALUES(100, 'workCenterOne', 1, NULL, 1, 'gotham', NULL, NULL); \ No newline at end of file diff --git a/loopback/locale/en.json b/loopback/locale/en.json index 9a3a1f52a..fdaea2697 100644 --- a/loopback/locale/en.json +++ b/loopback/locale/en.json @@ -225,5 +225,7 @@ "ticketCommercial": "The ticket {{ ticket }} for the salesperson {{ salesMan }} is in preparation. (automatically generated message)", "This password can only be changed by the user themselves": "This password can only be changed by the user themselves", "They're not your subordinate": "They're not your subordinate", - "InvoiceIn is already booked": "InvoiceIn is already booked" + "InvoiceIn is already booked": "InvoiceIn is already booked", + "This workCenter already exists": "This workCenter already exists", + "This workCenter is already assigned to this agency": "This workCenter is already assigned to this agency" } \ No newline at end of file diff --git a/loopback/locale/es.json b/loopback/locale/es.json index d7f9564fe..b218f03ec 100644 --- a/loopback/locale/es.json +++ b/loopback/locale/es.json @@ -353,5 +353,6 @@ "This password can only be changed by the user themselves": "Esta contraseña solo puede ser modificada por el propio usuario", "They're not your subordinate": "No es tu subordinado/a.", "No results found": "No se han encontrado resultados", - "InvoiceIn is already booked": "La factura recibida está contabilizada" + "InvoiceIn is already booked": "La factura recibida está contabilizada", + "This workCenter is already assigned to this agency": "This workCenter is already assigned to this agency" } \ No newline at end of file