From a48617e2679166420787a0f7789275463babcf34 Mon Sep 17 00:00:00 2001 From: joan Date: Mon, 8 Nov 2021 12:50:13 +0100 Subject: [PATCH 1/3] Group first --- modules/order/back/methods/order/filter.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/order/back/methods/order/filter.js b/modules/order/back/methods/order/filter.js index bd987dd5b..ddbaba5bd 100644 --- a/modules/order/back/methods/order/filter.js +++ b/modules/order/back/methods/order/filter.js @@ -172,11 +172,11 @@ module.exports = Self => { LEFT JOIN zoneEstimatedDelivery zed ON zed.zoneFk = t.zoneFk`); stmt.merge(conn.makeWhere(filter.where)); + stmt.merge(`GROUP BY id`); stmt.merge(conn.makePagination(filter)); stmts.push(stmt); stmt = new ParameterizedSQL(`SELECT * FROM tmp.filter`); - stmt.merge(`GROUP BY id`); stmt.merge(conn.makeOrderBy(filter.order)); const ordersIndex = stmts.push(stmt) - 1; From a3bb3122eddec7b2dd2780dbc1ac406af43f896b Mon Sep 17 00:00:00 2001 From: alex Date: Mon, 8 Nov 2021 14:08:44 +0100 Subject: [PATCH 2/3] fix(time-control): modify select & refactor dates --- .../back/methods/worker/getWorkedHours.js | 18 ++++++------------ modules/worker/front/time-control/index.js | 6 ++++-- 2 files changed, 10 insertions(+), 14 deletions(-) diff --git a/modules/worker/back/methods/worker/getWorkedHours.js b/modules/worker/back/methods/worker/getWorkedHours.js index 9957fca25..44f3eca3a 100644 --- a/modules/worker/back/methods/worker/getWorkedHours.js +++ b/modules/worker/back/methods/worker/getWorkedHours.js @@ -42,27 +42,21 @@ module.exports = Self => { const stmts = []; - const startedMinusOne = new Date(started); - startedMinusOne.setDate(started.getDate() - 1); - - const endedPlusOne = new Date(ended); - endedPlusOne.setDate(ended.getDate() + 1); - stmts.push(` DROP TEMPORARY TABLE IF EXISTS tmp.timeControlCalculate, tmp.timeBusinessCalculate `); - stmts.push(new ParameterizedSQL('CALL vn.timeControl_calculateByUser(?, ?, ?)', [userId, startedMinusOne, endedPlusOne])); + stmts.push(new ParameterizedSQL('CALL vn.timeControl_calculateByUser(?, ?, ?)', [userId, started, ended])); - stmts.push(new ParameterizedSQL('CALL vn.timeBusiness_calculateByUser(?, ?, ?)', [userId, startedMinusOne, endedPlusOne])); + stmts.push(new ParameterizedSQL('CALL vn.timeBusiness_calculateByUser(?, ?, ?)', [userId, started, ended])); const resultIndex = stmts.push(new ParameterizedSQL(` - SELECT tbc.dated, tbc.timeWorkSeconds expectedHours, tcc.timeWorkSeconds workedHours - FROM tmp.timeBusinessCalculate tbc - LEFT JOIN tmp.timeControlCalculate tcc ON tcc.dated = tbc.dated - WHERE tbc.dated BETWEEN ? AND ? + SELECT tcc.dated, tbc.timeWorkSeconds expectedHours, tcc.timeWorkSeconds workedHours + FROM tmp.timeControlCalculate tcc + LEFT JOIN tmp.timeBusinessCalculate tbc ON tcc.dated = tbc.dated + WHERE tcc.dated BETWEEN DATE(?) AND DATE(?) `, [started, ended])) - 1; stmts.push(` diff --git a/modules/worker/front/time-control/index.js b/modules/worker/front/time-control/index.js index 0fb5f9dbe..4c0793933 100644 --- a/modules/worker/front/time-control/index.js +++ b/modules/worker/front/time-control/index.js @@ -171,10 +171,11 @@ class Controller extends Section { from: from, to: to }; - + console.log(from, to); const query = `Workers/${this.$params.id}/getWorkedHours`; return this.$http.get(query, {params}).then(res => { const workDays = res.data; + console.log(res.data); const map = new Map(); for (const workDay of workDays) { @@ -212,7 +213,8 @@ class Controller extends Section { let todayInWeek = this.weekDays.find(day => day.dated.getTime() === today.getTime()); if (todayInWeek && todayInWeek.hours && todayInWeek.hours.length) { - const remainingTime = todayInWeek.workedHours ? ((todayInWeek.expectedHours - todayInWeek.workedHours) * 1000) : null; + const remainingTime = todayInWeek.workedHours ? + ((todayInWeek.expectedHours - todayInWeek.workedHours) * 1000) : null; const lastKnownEntry = todayInWeek.hours[todayInWeek.hours.length - 1]; const lastKnownTime = new Date(lastKnownEntry.timed).getTime(); const finishTimeStamp = lastKnownTime && remainingTime ? lastKnownTime + remainingTime : null; From 62cdf52227f829d04072f5a916001c8ddd4a3852 Mon Sep 17 00:00:00 2001 From: alex Date: Tue, 9 Nov 2021 10:09:44 +0100 Subject: [PATCH 3/3] refactor(time-control): getWorkedHours.spec --- .../back/methods/worker/specs/getWorkedHours.spec.js | 12 ++++++------ modules/worker/front/time-control/index.js | 2 -- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/modules/worker/back/methods/worker/specs/getWorkedHours.spec.js b/modules/worker/back/methods/worker/specs/getWorkedHours.spec.js index c06ff8502..3132a9003 100644 --- a/modules/worker/back/methods/worker/specs/getWorkedHours.spec.js +++ b/modules/worker/back/methods/worker/specs/getWorkedHours.spec.js @@ -1,17 +1,17 @@ -const app = require('vn-loopback/server/server'); +const models = require('vn-loopback/server/server').models; describe('Worker getWorkedHours()', () => { it(`should return the expected hours and the worked hours of a given date`, async() => { const workerID = 1106; - let started = new Date(); + const started = new Date(); started.setHours(0, 0, 0, 0); - let ended = new Date(); - ended.setHours(0, 0, 0, 0); + const ended = new Date(); + ended.setHours(23, 59, 59, 999); - const [result] = await app.models.Worker.getWorkedHours(workerID, started, ended); + const [result] = await models.Worker.getWorkedHours(workerID, started, ended); - expect(result.expectedHours).toEqual(28800); // 8:00 hours seconds + expect(result.expectedHours).toEqual(28800); // 8:00 hours in seconds expect(result.workedHours).toEqual(29400); // 8:10 hours in seconds }); }); diff --git a/modules/worker/front/time-control/index.js b/modules/worker/front/time-control/index.js index 4c0793933..96913c505 100644 --- a/modules/worker/front/time-control/index.js +++ b/modules/worker/front/time-control/index.js @@ -171,11 +171,9 @@ class Controller extends Section { from: from, to: to }; - console.log(from, to); const query = `Workers/${this.$params.id}/getWorkedHours`; return this.$http.get(query, {params}).then(res => { const workDays = res.data; - console.log(res.data); const map = new Map(); for (const workDay of workDays) {