From 272dbd210bc08003b8bac0e6fad47fea31ca3bdb Mon Sep 17 00:00:00 2001 From: carlossa Date: Mon, 25 Nov 2024 08:10:57 +0100 Subject: [PATCH] fix: refs #8222 fix deleteZone --- loopback/locale/en.json | 2 +- loopback/locale/es.json | 2 +- modules/zone/back/methods/zone/deleteZone.js | 6 +++--- modules/zone/back/methods/zone/specs/deleteZone.spec.js | 6 +++--- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/loopback/locale/en.json b/loopback/locale/en.json index 4b62be2be0..b0e33a42f9 100644 --- a/loopback/locale/en.json +++ b/loopback/locale/en.json @@ -240,5 +240,5 @@ "The height must be greater than 50cm": "The height must be greater than 50cm", "The maximum height of the wagon is 200cm": "The maximum height of the wagon is 200cm", "The quantity claimed cannot be greater than the quantity of the line": "The quantity claimed cannot be greater than the quantity of the line", - "There are tickets for this area, delete them first": "There are tickets for this area, delete them first" + "There are tickets to be invoiced for this area, please delete them first": "There are tickets to be invoiced for this area, please delete them first" } diff --git a/loopback/locale/es.json b/loopback/locale/es.json index 987935c7c3..a1d25f77b2 100644 --- a/loopback/locale/es.json +++ b/loopback/locale/es.json @@ -383,5 +383,5 @@ "No valid travel thermograph found": "No se encontró un termógrafo válido", "The quantity claimed cannot be greater than the quantity of the line": "La cantidad reclamada no puede ser mayor que la cantidad de la línea", "type cannot be blank": "Se debe rellenar el tipo", - "There are tickets for this area, delete them first": "Hay tickets para esta sección, borralos primero" + "There are tickets to be invoiced for this area, please delete them first": "Hay tickets para esta sección, borralos primero" } diff --git a/modules/zone/back/methods/zone/deleteZone.js b/modules/zone/back/methods/zone/deleteZone.js index 7432475b36..62d88509c8 100644 --- a/modules/zone/back/methods/zone/deleteZone.js +++ b/modules/zone/back/methods/zone/deleteZone.js @@ -51,9 +51,9 @@ module.exports = Self => { }; const ticketList = await models.Ticket.find(filter, myOptions); - - if (ticketList.length > 0) - throw new UserError('There are tickets for this area, delete them first'); + const hasRefFkFilled = ticketList.some(ticket => ticket.refFk !== null && ticket.refFk !== undefined); + if (hasRefFkFilled) + throw new UserError('There are tickets to be invoiced for this area, please delete them first'); await models.Zone.destroyById(id, myOptions); diff --git a/modules/zone/back/methods/zone/specs/deleteZone.spec.js b/modules/zone/back/methods/zone/specs/deleteZone.spec.js index aef7fd2900..4b67944f34 100644 --- a/modules/zone/back/methods/zone/specs/deleteZone.spec.js +++ b/modules/zone/back/methods/zone/specs/deleteZone.spec.js @@ -9,7 +9,7 @@ describe('zone deletezone()', () => { }; const ctx = {req: activeCtx}; const zoneId = 4; - const zoneId2 = 3; + const zoneId1 = 1; let ticketIDs; beforeAll(async() => { @@ -51,13 +51,13 @@ describe('zone deletezone()', () => { let error; try { const options = {transaction: tx}; - await models.Zone.deleteZone(ctx, zoneId2, options); + await models.Zone.deleteZone(ctx, zoneId1, options); await tx.rollback(); } catch (e) { error = e.message; await tx.rollback(); } - expect(error).toEqual('There are tickets for this area, delete them first'); + expect(error).toEqual('There are tickets to be invoiced for this area, please delete them first'); }); });