From a733bc8c2f6e658aeafe91c471b29b3af20f371e Mon Sep 17 00:00:00 2001 From: Pau Navarro Date: Wed, 16 Nov 2022 13:36:26 +0100 Subject: [PATCH 1/4] refs #4789 hasInvoice on ticket searchbar @3h30m --- modules/ticket/back/methods/ticket/filter.js | 9 +++++ .../back/methods/ticket/specs/filter.spec.js | 38 +++++++++++++++++++ modules/ticket/front/search-panel/index.html | 5 +++ .../ticket/front/search-panel/locale/es.yml | 1 + 4 files changed, 53 insertions(+) diff --git a/modules/ticket/back/methods/ticket/filter.js b/modules/ticket/back/methods/ticket/filter.js index da8f65be2..a2add2e82 100644 --- a/modules/ticket/back/methods/ticket/filter.js +++ b/modules/ticket/back/methods/ticket/filter.js @@ -88,6 +88,11 @@ module.exports = Self => { type: 'boolean', description: `Whether to show only tickets with route` }, + { + arg: 'hasInvoice', + type: 'boolean', + description: `Whether to show only tickets with invoice` + }, { arg: 'pending', type: 'boolean', @@ -199,6 +204,10 @@ module.exports = Self => { if (value == true) return {'t.routeFk': {neq: null}}; return {'t.routeFk': null}; + case 'hasInvoice': + if (value == true) + return {'t.refFk': {neq: null}}; + return {'t.refFk': null}; case 'pending': return {'st.isNotValidated': value}; case 'id': diff --git a/modules/ticket/back/methods/ticket/specs/filter.spec.js b/modules/ticket/back/methods/ticket/specs/filter.spec.js index c3dc40092..7d1613120 100644 --- a/modules/ticket/back/methods/ticket/specs/filter.spec.js +++ b/modules/ticket/back/methods/ticket/specs/filter.spec.js @@ -278,4 +278,42 @@ describe('ticket filter()', () => { throw e; } }); + + it('should return the tickets the invoice on false', async() => { + const tx = await models.Ticket.beginTransaction({}); + + try { + const options = {transaction: tx}; + + const ctx = {req: {accessToken: {userId: 9}}, args: {hasInvoice: true}}; + const filter = {}; + const result = await models.Ticket.filter(ctx, filter, options); + + expect(result.length).toEqual(6); + + await tx.rollback(); + } catch (e) { + await tx.rollback(); + throw e; + } + }); + + it('should return the tickets the invoice on null', async() => { + const tx = await models.Ticket.beginTransaction({}); + + try { + const options = {transaction: tx}; + + const ctx = {req: {accessToken: {userId: 9}}, args: {hasInvoice: null}}; + const filter = {}; + const result = await models.Ticket.filter(ctx, filter, options); + + expect(result.length).toEqual(27); + + await tx.rollback(); + } catch (e) { + await tx.rollback(); + throw e; + } + }); }); diff --git a/modules/ticket/front/search-panel/index.html b/modules/ticket/front/search-panel/index.html index b0d4963bd..7002f3dd6 100644 --- a/modules/ticket/front/search-panel/index.html +++ b/modules/ticket/front/search-panel/index.html @@ -141,6 +141,11 @@ ng-model="filter.hasRoute" triple-state="true"> + diff --git a/modules/ticket/front/search-panel/locale/es.yml b/modules/ticket/front/search-panel/locale/es.yml index 52cc04d6e..1d1c82d1a 100644 --- a/modules/ticket/front/search-panel/locale/es.yml +++ b/modules/ticket/front/search-panel/locale/es.yml @@ -13,6 +13,7 @@ Grouped States: Estado agrupado Days onward: Días adelante With problems: Con problemas Has route: Con ruta +Has invoice: Con factura Pending: Pendiente FREE: Libre DELIVERED: Servido From 0099b42fe3eb4cd96cd1a45dc53093d079c1bbb3 Mon Sep 17 00:00:00 2001 From: Pau Navarro Date: Mon, 21 Nov 2022 14:06:38 +0100 Subject: [PATCH 2/4] requested changes --- modules/ticket/back/methods/ticket/specs/filter.spec.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/ticket/back/methods/ticket/specs/filter.spec.js b/modules/ticket/back/methods/ticket/specs/filter.spec.js index 7d1613120..93ebdb0e7 100644 --- a/modules/ticket/back/methods/ticket/specs/filter.spec.js +++ b/modules/ticket/back/methods/ticket/specs/filter.spec.js @@ -39,7 +39,7 @@ describe('ticket filter()', () => { const filter = {}; const result = await models.Ticket.filter(ctx, filter, options); - expect(result.length).toEqual(6); + expect(result.length).toBeGreaterThan(3); await tx.rollback(); } catch (e) { From 4c4e0e109d3af0c08e3cf40834bb075cd230495d Mon Sep 17 00:00:00 2001 From: Pau Navarro Date: Wed, 23 Nov 2022 08:25:15 +0100 Subject: [PATCH 4/4] refactor test to use toBeGreaterThan --- modules/ticket/back/methods/ticket/specs/filter.spec.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/modules/ticket/back/methods/ticket/specs/filter.spec.js b/modules/ticket/back/methods/ticket/specs/filter.spec.js index 93ebdb0e7..1bcb90ed0 100644 --- a/modules/ticket/back/methods/ticket/specs/filter.spec.js +++ b/modules/ticket/back/methods/ticket/specs/filter.spec.js @@ -279,7 +279,7 @@ describe('ticket filter()', () => { } }); - it('should return the tickets the invoice on false', async() => { + it('should return the tickets with the invoice on false', async() => { const tx = await models.Ticket.beginTransaction({}); try { @@ -298,7 +298,7 @@ describe('ticket filter()', () => { } }); - it('should return the tickets the invoice on null', async() => { + it('should return the tickets with the invoice on null', async() => { const tx = await models.Ticket.beginTransaction({}); try { @@ -308,7 +308,7 @@ describe('ticket filter()', () => { const filter = {}; const result = await models.Ticket.filter(ctx, filter, options); - expect(result.length).toEqual(27); + expect(result.length).toBeGreaterThanOrEqual(27); await tx.rollback(); } catch (e) {