From ffa0ff650eb0321821fd221f86a142ad91a308ee Mon Sep 17 00:00:00 2001 From: vicent Date: Mon, 7 Nov 2022 12:21:14 +0100 Subject: [PATCH] feat: add time control --- db/dump/fixtures.sql | 1 - .../methods/worker-time-control/sendMail.js | 7 +-- .../specs/sendMail.spec.js | 48 ++----------------- modules/worker/back/model-config.json | 3 ++ .../models/worker-time-control-config.json | 18 +++++++ 5 files changed, 28 insertions(+), 49 deletions(-) create mode 100644 modules/worker/back/models/worker-time-control-config.json diff --git a/db/dump/fixtures.sql b/db/dump/fixtures.sql index 8160ae922..d875881b9 100644 --- a/db/dump/fixtures.sql +++ b/db/dump/fixtures.sql @@ -2715,7 +2715,6 @@ UPDATE `account`.`user` SET `hasGrant` = 1 WHERE `id` = 66; - INSERT INTO `vn`.`osTicketConfig` (`id`, `host`, `user`, `password`, `oldStatus`, `newStatusId`, `day`, `comment`, `hostDb`, `userDb`, `passwordDb`, `portDb`, `responseType`, `fromEmailId`, `replyTo`) VALUES (0, 'http://localhost:56596/scp', 'ostadmin', 'Admin1', 'open', 3, 60, 'Este CAU se ha cerrado automáticamente. Si el problema persiste responda a este mensaje.', 'localhost', 'osticket', 'osticket', 40003, 'reply', 1, 'all'); diff --git a/modules/worker/back/methods/worker-time-control/sendMail.js b/modules/worker/back/methods/worker-time-control/sendMail.js index 243b10cf6..2f9559b3a 100644 --- a/modules/worker/back/methods/worker-time-control/sendMail.js +++ b/modules/worker/back/methods/worker-time-control/sendMail.js @@ -162,6 +162,8 @@ module.exports = Self => { let previousWorkerFk = days[index][0].workerFk; let previousReceiver = days[index][0].receiver; + const workerTimeControlConfig = await models.WorkerTimeControlConfig.findOne(null, myOptions); + for (let day of days[index]) { workerFk = day.workerFk; if (day.timeWorkDecimal > 0 && day.timeWorkedDecimal == null @@ -176,7 +178,7 @@ module.exports = Self => { isSendMail: true }, myOptions); - if (day.timeWorkDecimal >= 5) { + if (day.timeWorkDecimal >= workerTimeControlConfig.timeToBreakTime / 3600) { await models.WorkerTimeControl.create({ userFk: day.workerFk, timed: timed.setHours(9), @@ -227,7 +229,6 @@ module.exports = Self => { for (let journey of journeys) { const timeTableDecimal = timeTableDecimalInSeconds / 3600; - console.log(timeTableDecimal); if (day.timeWorkDecimal == timeTableDecimal) { const timed = new Date(day.dated); const [startHours, startMinutes, startSeconds] = getTime(journey.start); @@ -273,7 +274,7 @@ module.exports = Self => { } } - if (day.timeWorkDecimal >= 5) { + if (day.timeWorkDecimal >= workerTimeControlConfig.timeToBreakTime / 3600) { const minStart = journeys.reduce(function(prev, curr) { return curr.start < prev.start ? curr : prev; }); diff --git a/modules/worker/back/methods/worker-time-control/specs/sendMail.spec.js b/modules/worker/back/methods/worker-time-control/specs/sendMail.spec.js index f05432ba2..ec3012e82 100644 --- a/modules/worker/back/methods/worker-time-control/specs/sendMail.spec.js +++ b/modules/worker/back/methods/worker-time-control/specs/sendMail.spec.js @@ -1,4 +1,3 @@ -/* eslint max-len: ["error", { "code": 150 }]*/ const models = require('vn-loopback/server/server').models; fdescribe('workerTimeControl sendMail()', () => { @@ -18,7 +17,7 @@ fdescribe('workerTimeControl sendMail()', () => { jasmine.DEFAULT_TIMEOUT_INTERVAL = 10000; }); - it('should fill time control of a worker...', async() => { + it('should fill time control of a worker without records in Journey and and with rest', async() => { const tx = await models.WorkerTimeControl.beginTransaction({}); try { @@ -42,7 +41,7 @@ fdescribe('workerTimeControl sendMail()', () => { } }); - it('should fill time control of a worker2...', async() => { + it('should fill time control of a worker without records in Journey and and without rest', async() => { const workdayOf20Hours = 3; const tx = await models.WorkerTimeControl.beginTransaction({}); @@ -69,8 +68,7 @@ fdescribe('workerTimeControl sendMail()', () => { } }); - it('should fill time control of a worker3...', async() => { - const workdayOf20Hours = 3; + it('should fill time control of a worker with records in Journey', async() => { const tx = await models.WorkerTimeControl.beginTransaction({}); try { @@ -87,46 +85,6 @@ fdescribe('workerTimeControl sendMail()', () => { const workerTimeControl = await models.WorkerTimeControl.find({ where: {userFk: workerId} }, options); - console.log(workerTimeControl); - - expect(workerTimeControl[0].timed.getHours()).toEqual(9); - expect(workerTimeControl[2].timed.getHours()).toEqual(10); - expect(`${workerTimeControl[3].timed.getHours()}:${workerTimeControl[3].timed.getMinutes()}`).toEqual('10:20'); - expect(workerTimeControl[1].timed.getHours()).toEqual(13); - expect(workerTimeControl[4].timed.getHours()).toEqual(14); - expect(workerTimeControl[5].timed.getHours()).toEqual(19); - - await tx.rollback(); - } catch (e) { - await tx.rollback(); - throw e; - } - }); - - it('should fill time control of a worker4...', async() => { - const workdayOf20Hours = 3; - const tx = await models.WorkerTimeControl.beginTransaction({}); - - try { - const options = {transaction: tx}; - query = `UPDATE business b - SET b.calendarTypeFk = ? - WHERE b.workerFk = ?; `; - await models.WorkerTimeControl.rawSql(query, [workdayOf20Hours, workerId], options); - - query = `INSERT INTO postgresql.journey(journey_id, day_id, start, end, business_id) - VALUES - (1, 1, '09:00:00', '13:00:00', ?), - (2, 1, '14:00:00', '19:00:00', ?), - (3, 2, '12:30:00', '19:00:00', ?);`; - await models.WorkerTimeControl.rawSql(query, [workerId, workerId, workerId], options); - - await models.WorkerTimeControl.sendMail(ctx, options); - - const workerTimeControl = await models.WorkerTimeControl.find({ - where: {userFk: workerId} - }, options); - console.log(workerTimeControl); expect(workerTimeControl[0].timed.getHours()).toEqual(9); expect(workerTimeControl[2].timed.getHours()).toEqual(10); diff --git a/modules/worker/back/model-config.json b/modules/worker/back/model-config.json index b2051069b..3f3416504 100644 --- a/modules/worker/back/model-config.json +++ b/modules/worker/back/model-config.json @@ -65,6 +65,9 @@ "WorkerLog": { "dataSource": "vn" }, + "WorkerTimeControlConfig": { + "dataSource": "vn" + }, "WorkerTimeControlParams": { "dataSource": "vn" }, diff --git a/modules/worker/back/models/worker-time-control-config.json b/modules/worker/back/models/worker-time-control-config.json new file mode 100644 index 000000000..4c12ce5d7 --- /dev/null +++ b/modules/worker/back/models/worker-time-control-config.json @@ -0,0 +1,18 @@ +{ + "name": "WorkerTimeControlConfig", + "base": "VnModel", + "options": { + "mysql": { + "table": "workerTimeControlConfig" + } + }, + "properties": { + "id": { + "id": true, + "type": "number" + }, + "timeToBreakTime": { + "type": "number" + } + } +} \ No newline at end of file