From 0370cbf20704c28b8a2f76d90069ae1a48e3c62b Mon Sep 17 00:00:00 2001 From: joan Date: Wed, 1 Sep 2021 11:27:24 +0200 Subject: [PATCH 1/2] feat(Searchbar): You can now filter by a ticket collection Refs: 3068 --- modules/ticket/back/methods/ticket/filter.js | 16 +++++++++++++++- modules/ticket/front/search-panel/index.html | 5 +++++ modules/ticket/front/search-panel/locale/es.yml | 3 ++- 3 files changed, 22 insertions(+), 2 deletions(-) diff --git a/modules/ticket/back/methods/ticket/filter.js b/modules/ticket/back/methods/ticket/filter.js index 9038b0886..79006e77d 100644 --- a/modules/ticket/back/methods/ticket/filter.js +++ b/modules/ticket/back/methods/ticket/filter.js @@ -107,7 +107,12 @@ module.exports = Self => { arg: 'alertLevel', type: 'number', description: `The alert level of the tickets` - } + }, + { + arg: 'collectionFk', + type: 'number', + description: `The collection id filter` + }, ], returns: { type: ['object'], @@ -269,6 +274,15 @@ module.exports = Self => { }); } + if (args.collectionFk) { + stmt.merge({ + sql: ` + JOIN collection cll ON cll.id = ? + JOIN ticketCollection tc ON tc.collectionFk = cll.id AND tc.ticketFk = t.id`, + params: [args.collectionFk] + }); + } + stmt.merge(conn.makeWhere(filter.where)); stmts.push(stmt); diff --git a/modules/ticket/front/search-panel/index.html b/modules/ticket/front/search-panel/index.html index d0b77b9de..79dfabb58 100644 --- a/modules/ticket/front/search-panel/index.html +++ b/modules/ticket/front/search-panel/index.html @@ -110,6 +110,11 @@ ng-model="filter.provinceFk" url="Provinces"> + + Date: Wed, 1 Sep 2021 11:48:21 +0200 Subject: [PATCH 2/2] Updated unit tests --- .../collection/spec/newCollection.spec.js | 2 +- db/dump/fixtures.sql | 5 +++++ .../back/methods/ticket/specs/filter.spec.js | 19 +++++++++++++++++++ 3 files changed, 25 insertions(+), 1 deletion(-) diff --git a/back/methods/collection/spec/newCollection.spec.js b/back/methods/collection/spec/newCollection.spec.js index f57716f16..6fbf9af8c 100644 --- a/back/methods/collection/spec/newCollection.spec.js +++ b/back/methods/collection/spec/newCollection.spec.js @@ -6,6 +6,6 @@ describe('newCollection()', () => { let response = await app.models.Collection.newCollection(ctx, 1, 1, 1); expect(response.length).toBeGreaterThan(0); - expect(response[0].ticketFk).toEqual(1); + expect(response[0].ticketFk).toEqual(2); }); }); diff --git a/db/dump/fixtures.sql b/db/dump/fixtures.sql index 867a830df..995fa165f 100644 --- a/db/dump/fixtures.sql +++ b/db/dump/fixtures.sql @@ -1064,6 +1064,11 @@ INSERT INTO `vn`.`collection`(`id`, `workerFk`, `stateFk`) (1, 1106, 5), (2, 1106, 14); +INSERT INTO `vn`.`ticketCollection`(`id`, `ticketFk`, `collectionFk`) + VALUES + (2, 2, 1), + (3, 3, 2); + INSERT INTO `vn`.`parking` (`column`, `row`, `sectorFk`, `code`, `pickingOrder`) VALUES ('100', '01', 1, '100-01', 1); diff --git a/modules/ticket/back/methods/ticket/specs/filter.spec.js b/modules/ticket/back/methods/ticket/specs/filter.spec.js index 743a3ba81..01a652b73 100644 --- a/modules/ticket/back/methods/ticket/specs/filter.spec.js +++ b/modules/ticket/back/methods/ticket/specs/filter.spec.js @@ -202,4 +202,23 @@ describe('ticket filter()', () => { throw e; } }); + + it('should return the tickets belonging to the collection id 1', async() => { + const tx = await models.Ticket.beginTransaction({}); + + try { + const options = {transaction: tx}; + + const ctx = {req: {accessToken: {userId: 18}}, args: {collectionFk: 1}}; + const filter = {}; + const result = await models.Ticket.filter(ctx, filter, options); + + expect(result.length).toEqual(2); + + await tx.rollback(); + } catch (e) { + await tx.rollback(); + throw e; + } + }); });