diff --git a/loopback/locale/en.json b/loopback/locale/en.json index fdd39325b..b1cfd737f 100644 --- a/loopback/locale/en.json +++ b/loopback/locale/en.json @@ -245,6 +245,6 @@ "Invalid or expired verification code": "Invalid or expired verification code", "Payment method is required": "Payment method is required", "The raid information is not correct": "The raid information is not correct", - "Sales already moved": "Sales already moved" - + "Sales already moved": "Sales already moved", + "There are tickets to be invoiced": "There are tickets to be invoiced for this zone, please delete them first" } diff --git a/loopback/locale/es.json b/loopback/locale/es.json index 4e691f375..6cd158eed 100644 --- a/loopback/locale/es.json +++ b/loopback/locale/es.json @@ -388,5 +388,6 @@ "ticketLostExpedition": "El ticket [{{ticketId}}]({{{ticketUrl}}}) tiene la siguiente expedición perdida:{{ expeditionId }}", "The web user's email already exists": "El correo del usuario web ya existe", "Sales already moved": "Ya han sido transferidas", - "The raid information is not correct": "La información de la redada no es correcta" + "The raid information is not correct": "La información de la redada no es correcta", + "There are tickets to be invoiced": "Hay tickets para esta zona, borralos primero" } diff --git a/modules/zone/back/methods/zone/deleteZone.js b/modules/zone/back/methods/zone/deleteZone.js index 7432475b3..e2e01a949 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 hasRefFk = ticketList.some(ticket => ticket.refFk); + if (hasRefFk) + throw new UserError('There are tickets to be invoiced'); 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 aef7fd290..510713f9e 100644 --- a/modules/zone/back/methods/zone/specs/deleteZone.spec.js +++ b/modules/zone/back/methods/zone/specs/deleteZone.spec.js @@ -8,14 +8,14 @@ describe('zone deletezone()', () => { __: value => value }; const ctx = {req: activeCtx}; - const zoneId = 4; - const zoneId2 = 3; let ticketIDs; beforeAll(async() => { spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({ active: activeCtx }); + + const zoneId = 4; const originalTickets = await models.Ticket.find({ where: { zoneFk: zoneId @@ -29,7 +29,7 @@ describe('zone deletezone()', () => { it('should delete a zone and update their tickets', async() => { const tx = await models.Zone.beginTransaction({}); - + const zoneId = 4; try { const options = {transaction: tx}; await models.Zone.deleteZone(ctx, zoneId, options); @@ -47,17 +47,18 @@ describe('zone deletezone()', () => { it('should not delete the zone if it has tickets', async() => { const tx = await models.Zone.beginTransaction({}); + const zoneId = 1; let error; try { const options = {transaction: tx}; - await models.Zone.deleteZone(ctx, zoneId2, options); + await models.Zone.deleteZone(ctx, zoneId, 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'); }); });