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 a1e2256f6..3da674cb1 100644 --- a/db/dump/fixtures.sql +++ b/db/dump/fixtures.sql @@ -1072,6 +1072,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/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/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; + } + }); }); 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"> + +