diff --git a/db/dump/fixtures.sql b/db/dump/fixtures.sql index 9f3a5e717..2b22dcd0a 100644 --- a/db/dump/fixtures.sql +++ b/db/dump/fixtures.sql @@ -1894,6 +1894,10 @@ INSERT INTO `postgresql`.`business` (`client_id`, `provider_id`, `date_start`, ` FROM `postgresql`.`profile` `p` WHERE `p`.`profile_id` = 1109; +UPDATE `postgresql`.`business` + SET `payedHolidays`= 8 + WHERE `business_id`= 1106; + INSERT INTO `postgresql`.`business_labour` (`business_id`, `notes`, `department_id`, `professional_category_id`, `incentivo`, `calendar_labour_type_id`, `porhoras`, `labour_agreement_id`, `workcenter_id`) VALUES (1111, NULL, 23, 1, 0.0, 1, 1, 1, 1); diff --git a/modules/worker/back/methods/worker/holidays.js b/modules/worker/back/methods/worker/holidays.js index 339b84b7b..7f093a330 100644 --- a/modules/worker/back/methods/worker/holidays.js +++ b/modules/worker/back/methods/worker/holidays.js @@ -57,25 +57,9 @@ module.exports = Self => { ended.setDate(0); ended.setHours(23, 59, 59, 59); - const filter = { - where: { - and: [ - {workerFk: id}, - { - or: [ - {started: {between: [started, ended]}}, - {ended: {between: [started, ended]}}, - {and: [{started: {lt: started}}, {ended: {gt: ended}}]}, - {and: [{started: {lt: started}}, {ended: null}]} - ] - } - ], - - } - }; - const contracts = await models.WorkerLabour.find(filter, myOptions); - let [firstContract] = contracts; - const payedHolidays = firstContract.payedHolidays; + const filter = {where: {businessFk: args.businessFk}}; + const contract = await models.WorkerLabour.findOne(filter, myOptions); + const payedHolidays = contract.payedHolidays; let queryIndex; const year = started.getFullYear(); diff --git a/modules/worker/back/methods/worker/specs/holidays.spec.js b/modules/worker/back/methods/worker/specs/holidays.spec.js index 317bc8f0f..d8310b738 100644 --- a/modules/worker/back/methods/worker/specs/holidays.spec.js +++ b/modules/worker/back/methods/worker/specs/holidays.spec.js @@ -27,4 +27,15 @@ describe('Worker holidays()', () => { expect(result.totalHolidays).toEqual(27.5); expect(result.holidaysEnjoyed).toEqual(5); }); + + it('should now get the payed holidays calendar for a worker', async() => { + const now = new Date(); + const year = now.getFullYear(); + + ctx.args = {businessFk: businessId, year: year}; + + const result = await app.models.Worker.holidays(ctx, workerId); + + expect(result.payedHolidays).toEqual(8); + }); });