From f24aa2c80130ce509ffc9e7b4e03a5c9b42a211d Mon Sep 17 00:00:00 2001 From: carlossa Date: Mon, 17 Jul 2023 13:27:27 +0200 Subject: [PATCH 1/5] pop vehicle error --- back/models/invoice-in.js | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 back/models/invoice-in.js diff --git a/back/models/invoice-in.js b/back/models/invoice-in.js new file mode 100644 index 000000000..6fa1fa0e1 --- /dev/null +++ b/back/models/invoice-in.js @@ -0,0 +1,9 @@ +let UserError = require('vn-loopback/util/user-error'); + +module.exports = Self => { + Self.rewriteDbError(function(err) { + if (err.code === 'ER_ROW_IS_REFERENCED') + return new UserError(`This invoice has a linked vehicle.`); + return err; + }); +}; From 10e726c48656803a2c076adc066e43bff49a0595 Mon Sep 17 00:00:00 2001 From: carlossa Date: Mon, 17 Jul 2023 13:51:16 +0200 Subject: [PATCH 2/5] move vehicleInvoice --- .../invoiceIn/back/models/invoiceInVehicle.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename back/models/invoice-in.js => modules/invoiceIn/back/models/invoiceInVehicle.js (81%) diff --git a/back/models/invoice-in.js b/modules/invoiceIn/back/models/invoiceInVehicle.js similarity index 81% rename from back/models/invoice-in.js rename to modules/invoiceIn/back/models/invoiceInVehicle.js index 6fa1fa0e1..cf45bf741 100644 --- a/back/models/invoice-in.js +++ b/modules/invoiceIn/back/models/invoiceInVehicle.js @@ -2,7 +2,7 @@ let UserError = require('vn-loopback/util/user-error'); module.exports = Self => { Self.rewriteDbError(function(err) { - if (err.code === 'ER_ROW_IS_REFERENCED') + if (err.code === 'ER_ROW_IS_REFERENCED_2') return new UserError(`This invoice has a linked vehicle.`); return err; }); From a5d1c68511060e930ec2a802542ec591913c728c Mon Sep 17 00:00:00 2001 From: carlossa Date: Mon, 17 Jul 2023 14:07:45 +0200 Subject: [PATCH 3/5] change err and traduction --- loopback/locale/es.json | 3 ++- modules/invoiceIn/back/models/invoice-in.js | 8 ++++++++ modules/invoiceIn/back/models/invoiceInVehicle.js | 1 + 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/loopback/locale/es.json b/loopback/locale/es.json index 4086cfa4a..08f5bf765 100644 --- a/loopback/locale/es.json +++ b/loopback/locale/es.json @@ -305,5 +305,6 @@ "The renew period has not been exceeded": "El periodo de renovación no ha sido superado", "Valid priorities": "Prioridades válidas: %d", "Negative basis of tickets": "Base negativa para los tickets: {{ticketsIds}}", - "You cannot assign/remove an alias that you are not assigned to": "No puede asignar/eliminar un alias que no tenga asignado" + "You cannot assign/remove an alias that you are not assigned to": "No puede asignar/eliminar un alias que no tenga asignado", + "This invoice has a linked vehicle.": "Esta factura tiene un vehiculo vinculado" } diff --git a/modules/invoiceIn/back/models/invoice-in.js b/modules/invoiceIn/back/models/invoice-in.js index 51905ccb8..0efa6c309 100644 --- a/modules/invoiceIn/back/models/invoice-in.js +++ b/modules/invoiceIn/back/models/invoice-in.js @@ -1,3 +1,5 @@ +const UserError = require('vn-loopback/util/user-error'); + module.exports = Self => { require('../methods/invoice-in/filter')(Self); require('../methods/invoice-in/summary')(Self); @@ -7,4 +9,10 @@ module.exports = Self => { require('../methods/invoice-in/invoiceInPdf')(Self); require('../methods/invoice-in/invoiceInEmail')(Self); require('../methods/invoice-in/getSerial')(Self); + Self.rewriteDbError(function(err) { + console.log(err); + if (err.code === 'ER_ROW_IS_REFERENCED_2') + return new UserError(`This invoice has a linked vehicle.`); + return err; + }); }; diff --git a/modules/invoiceIn/back/models/invoiceInVehicle.js b/modules/invoiceIn/back/models/invoiceInVehicle.js index cf45bf741..7fa780142 100644 --- a/modules/invoiceIn/back/models/invoiceInVehicle.js +++ b/modules/invoiceIn/back/models/invoiceInVehicle.js @@ -2,6 +2,7 @@ let UserError = require('vn-loopback/util/user-error'); module.exports = Self => { Self.rewriteDbError(function(err) { + console.log(err); if (err.code === 'ER_ROW_IS_REFERENCED_2') return new UserError(`This invoice has a linked vehicle.`); return err; From 52f58a92c85f78d978bec7304816bef5b55c2d2f Mon Sep 17 00:00:00 2001 From: carlossa Date: Mon, 17 Jul 2023 14:11:05 +0200 Subject: [PATCH 4/5] refs err.sqlMessage --- modules/invoiceIn/back/models/invoice-in.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/modules/invoiceIn/back/models/invoice-in.js b/modules/invoiceIn/back/models/invoice-in.js index 0efa6c309..82e0bf078 100644 --- a/modules/invoiceIn/back/models/invoice-in.js +++ b/modules/invoiceIn/back/models/invoice-in.js @@ -10,8 +10,7 @@ module.exports = Self => { require('../methods/invoice-in/invoiceInEmail')(Self); require('../methods/invoice-in/getSerial')(Self); Self.rewriteDbError(function(err) { - console.log(err); - if (err.code === 'ER_ROW_IS_REFERENCED_2') + if (err.code === 'ER_ROW_IS_REFERENCED_2' && err.sqlMessage.includes('vehicleInvoiceIn')) return new UserError(`This invoice has a linked vehicle.`); return err; }); From 47e8fab8d9401ce78c6baa04a6c1667f59e786c6 Mon Sep 17 00:00:00 2001 From: carlossa Date: Mon, 17 Jul 2023 19:51:46 +0200 Subject: [PATCH 5/5] refs remove --- modules/invoiceIn/back/models/invoiceInVehicle.js | 10 ---------- 1 file changed, 10 deletions(-) delete mode 100644 modules/invoiceIn/back/models/invoiceInVehicle.js diff --git a/modules/invoiceIn/back/models/invoiceInVehicle.js b/modules/invoiceIn/back/models/invoiceInVehicle.js deleted file mode 100644 index 7fa780142..000000000 --- a/modules/invoiceIn/back/models/invoiceInVehicle.js +++ /dev/null @@ -1,10 +0,0 @@ -let UserError = require('vn-loopback/util/user-error'); - -module.exports = Self => { - Self.rewriteDbError(function(err) { - console.log(err); - if (err.code === 'ER_ROW_IS_REFERENCED_2') - return new UserError(`This invoice has a linked vehicle.`); - return err; - }); -};