diff --git a/db/dump/fixtures.sql b/db/dump/fixtures.sql index ccc1b7d1d..2b70cf2be 100644 --- a/db/dump/fixtures.sql +++ b/db/dump/fixtures.sql @@ -601,11 +601,11 @@ INSERT INTO `vn`.`ticketTracking`(`ticketFk`, `stateFk`, `workerFk`, `created`) (12, 3, 19, NOW()), (13, 3, 19, NOW()), (14, 3, 19, NOW()), - (15, 3, 19, NOW()), + (15, 2, 19, NOW()), (16, 3, 19, NOW()), - (17, 3, 19, NOW()), - (18, 3, 19, NOW()), - (19, 3, 19, NOW()), + (17, 2, 19, NOW()), + (18, 2, 19, NOW()), + (19, 2, 19, NOW()), (20, 1, 19, DATE_ADD(NOW(), INTERVAL +1 MONTH)), (21, 1, 19, DATE_ADD(NOW(), INTERVAL +1 MONTH)), (22, 1, 19, DATE_ADD(NOW(), INTERVAL +1 MONTH)), diff --git a/modules/ticket/back/methods/ticket/filter.js b/modules/ticket/back/methods/ticket/filter.js index ddb55301b..3a34be442 100644 --- a/modules/ticket/back/methods/ticket/filter.js +++ b/modules/ticket/back/methods/ticket/filter.js @@ -265,7 +265,7 @@ module.exports = Self => { LEFT JOIN tmp.ticketProblems tp ON tp.ticketFk = f.id LEFT JOIN tmp.ticketTotal tt ON tt.ticketFk = f.id`); - if (args.problems != undefined && (!args.from || !args.to)) + if (args.problems != undefined && (!args.from && !args.to)) throw new UserError('Choose a date range or days forward'); let condition; diff --git a/modules/ticket/back/methods/ticket/specs/deleteStowaway.spec.js b/modules/ticket/back/methods/ticket/specs/deleteStowaway.spec.js index bd6fd327a..56375940d 100644 --- a/modules/ticket/back/methods/ticket/specs/deleteStowaway.spec.js +++ b/modules/ticket/back/methods/ticket/specs/deleteStowaway.spec.js @@ -17,7 +17,7 @@ describe('ticket deleteStowaway()', () => { await app.models.Stowaway.rawSql( `CALL ticketStateUpdate(?, ?)`, [shipId, 'OK']); await app.models.Stowaway.rawSql( - `CALL ticketStateUpdate(?, ?)`, [stowawayId, 'OK']); + `CALL ticketStateUpdate(?, ?)`, [stowawayId, 'FREE']); }); it('should create an stowaway', async() => { @@ -97,6 +97,6 @@ describe('ticket deleteStowaway()', () => { } }); - expect(shipState.name).toEqual('OK'); + expect(shipState.name).toEqual('Libre'); }); }); diff --git a/modules/ticket/back/methods/ticket/specs/filter.spec.js b/modules/ticket/back/methods/ticket/specs/filter.spec.js index 4aa1b3a77..312b95ad5 100644 --- a/modules/ticket/back/methods/ticket/specs/filter.spec.js +++ b/modules/ticket/back/methods/ticket/specs/filter.spec.js @@ -11,7 +11,16 @@ describe('ticket filter()', () => { }); it('should return the tickets matching the problems on true', async() => { - const ctx = {req: {accessToken: {userId: 9}}, args: {problems: true}}; + const yesterday = new Date(); + yesterday.setHours(0, 0, 0, 0); + const today = new Date(); + today.setHours(23, 59, 59, 59); + + const ctx = {req: {accessToken: {userId: 9}}, args: { + problems: true, + from: yesterday, + to: today + }}; const filter = {}; const result = await app.models.Ticket.filter(ctx, filter); @@ -19,11 +28,21 @@ describe('ticket filter()', () => { }); it('should return the tickets matching the problems on false', async() => { - const ctx = {req: {accessToken: {userId: 9}}, args: {problems: false}}; + const yesterday = new Date(); + yesterday.setDate(yesterday.getDate() - 1); + yesterday.setHours(0, 0, 0, 0); + const today = new Date(); + today.setHours(23, 59, 59, 59); + + const ctx = {req: {accessToken: {userId: 9}}, args: { + problems: false, + from: yesterday, + to: today + }}; const filter = {}; const result = await app.models.Ticket.filter(ctx, filter); - expect(result.length).toEqual(20); + expect(result.length).toEqual(11); }); it('should return the tickets matching the problems on null', async() => { @@ -52,10 +71,10 @@ describe('ticket filter()', () => { 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'); + expect(result.length).toEqual(7); + expect(firstRow.state).toEqual('Libre'); + expect(secondRow.state).toEqual('Libre'); + expect(thirdRow.state).toEqual('Libre'); }); it('should return the tickets that are not pending', async() => { diff --git a/modules/ticket/front/main/index.html b/modules/ticket/front/main/index.html index a21b28992..7a02ce8ca 100644 --- a/modules/ticket/front/main/index.html +++ b/modules/ticket/front/main/index.html @@ -9,7 +9,8 @@ panel="vn-ticket-search-panel" info="Search ticket by id or alias" model="model" - fetch-params="$ctrl.fetchParams($params)"> + fetch-params="$ctrl.fetchParams($params)" + suggested-filter="$ctrl.defaultFilter"> diff --git a/modules/ticket/front/main/index.js b/modules/ticket/front/main/index.js index bd4718176..6b919c474 100644 --- a/modules/ticket/front/main/index.js +++ b/modules/ticket/front/main/index.js @@ -2,10 +2,15 @@ import ngModule from '../module'; import ModuleMain from 'salix/components/module-main'; export default class Ticket extends ModuleMain { - fetchParams($params) { - if (!Object.entries($params).length) - $params.scopeDays = 1; + constructor() { + super(); + this.defaultFilter = { + scopeDays: 1 + }; + } + + fetchParams($params) { if (typeof $params.scopeDays === 'number') { const from = new Date(); from.setHours(0, 0, 0, 0);