From 7e694c3e803bc60eed403fe69004a0bf4d7deac3 Mon Sep 17 00:00:00 2001 From: Joan Sanchez Date: Mon, 2 Mar 2020 11:35:43 +0100 Subject: [PATCH] 2073 - Filter by pending tickets --- modules/ticket/back/methods/ticket/filter.js | 18 +++++++++-- .../back/methods/ticket/specs/filter.spec.js | 30 ++++++++++++++++++- modules/ticket/front/search-panel/index.html | 8 ++++- .../ticket/front/search-panel/locale/es.yml | 4 ++- 4 files changed, 55 insertions(+), 5 deletions(-) diff --git a/modules/ticket/back/methods/ticket/filter.js b/modules/ticket/back/methods/ticket/filter.js index fa3067c17..aff26c63e 100644 --- a/modules/ticket/back/methods/ticket/filter.js +++ b/modules/ticket/back/methods/ticket/filter.js @@ -67,6 +67,10 @@ module.exports = Self => { arg: 'problems', type: 'Boolean', description: `Whether to show only tickets with problems` + }, { + arg: 'pending', + type: 'Boolean', + description: `Whether to show only tickets with state 'Pending'` }, { arg: 'mine', type: 'Boolean', @@ -130,7 +134,7 @@ module.exports = Self => { dateTo.setHours(23, 59, 0, 0); } - let where = buildFilter(ctx.args, (param, value) => { + const where = buildFilter(ctx.args, (param, value) => { switch (param) { case 'search': return /^\d+$/.test(value) @@ -155,6 +159,17 @@ module.exports = Self => { return {'c.salesPersonFk': {inq: teamIds}}; case 'alertLevel': return {'ts.alertLevel': value}; + case 'pending': + if (value) { + return {and: [ + {'st.alertLevel': 0}, + {'st.code': {neq: 'OK'}} + ]}; + } else { + return {and: [ + {'st.alertLevel': {gt: 0}} + ]}; + } case 'id': case 'clientFk': case 'agencyModeFk': @@ -244,7 +259,6 @@ module.exports = Self => { LEFT JOIN tmp.ticketProblems tp ON tp.ticketFk = f.id LEFT JOIN tmp.ticketTotal tt ON tt.ticketFk = f.id`); - let condition; let hasProblem; let range; diff --git a/modules/ticket/back/methods/ticket/specs/filter.spec.js b/modules/ticket/back/methods/ticket/specs/filter.spec.js index 656f99d65..faaeb82c0 100644 --- a/modules/ticket/back/methods/ticket/specs/filter.spec.js +++ b/modules/ticket/back/methods/ticket/specs/filter.spec.js @@ -41,6 +41,34 @@ describe('ticket filter()', () => { const firstRow = result[0]; expect(result.length).toEqual(1); - expect(firstRow.ticketFk).toEqual(11); + expect(firstRow.id).toEqual(11); + }); + + it('should return the tickets with grouped state "Pending" and not "Ok"', async() => { + const ctx = {req: {accessToken: {userId: 9}}, args: {pending: true}}; + const filter = {}; + const result = await app.models.Ticket.filter(ctx, filter); + const firstRow = result[0]; + const secondRow = result[1]; + const thirdRow = result[2]; + + expect(result.length).toEqual(3); + expect(firstRow.state).toEqual('Arreglar'); + expect(secondRow.state).toEqual('Arreglar'); + expect(thirdRow.state).toEqual('Arreglar'); + }); + + it('should return the tickets that are not pending', async() => { + const ctx = {req: {accessToken: {userId: 9}}, args: {pending: false}}; + const filter = {}; + const result = await app.models.Ticket.filter(ctx, filter); + const firstRow = result[0]; + const secondRow = result[1]; + const thirdRow = result[2]; + + expect(result.length).toEqual(13); + expect(firstRow.state).toEqual('Entregado'); + expect(secondRow.state).toEqual('Entregado'); + expect(thirdRow.state).toEqual('Entregado'); }); }); diff --git a/modules/ticket/front/search-panel/index.html b/modules/ticket/front/search-panel/index.html index ae5e152c6..e2d831994 100644 --- a/modules/ticket/front/search-panel/index.html +++ b/modules/ticket/front/search-panel/index.html @@ -113,10 +113,16 @@ + + diff --git a/modules/ticket/front/search-panel/locale/es.yml b/modules/ticket/front/search-panel/locale/es.yml index 0fcfdaa58..2f303ff2d 100644 --- a/modules/ticket/front/search-panel/locale/es.yml +++ b/modules/ticket/front/search-panel/locale/es.yml @@ -10,4 +10,6 @@ Province: Provincia My team: Mi equipo Order id: Id pedido Grouped States: Estado agrupado -Days onward: Días adelante \ No newline at end of file +Days onward: Días adelante +With problems: Con problemas +Pending: Pendientes \ No newline at end of file