From 7c57f9412ca75ae7a5294e21f324e51bd9a18e3a Mon Sep 17 00:00:00 2001 From: cxcarvaj Date: Thu, 10 Feb 2022 09:27:21 -0500 Subject: [PATCH 1/4] Changes in CLOCK_OUT_MESSAGE_MIDNIGHT --- nodejs-functions/src/handlers/automatic-clock-outs/constants.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nodejs-functions/src/handlers/automatic-clock-outs/constants.js b/nodejs-functions/src/handlers/automatic-clock-outs/constants.js index 1a104c1..9f8f20c 100644 --- a/nodejs-functions/src/handlers/automatic-clock-outs/constants.js +++ b/nodejs-functions/src/handlers/automatic-clock-outs/constants.js @@ -1,6 +1,6 @@ const constants = { CLOCK_OUT_MESSAGE : 'OMG %user_name%!, you have been working more than 12 hours in a row. \nPlease take a break and visit https://timetracker.ioet.com/ to set the right end time for your entries, we just did a clock out for you :wink:', - CLOCK_OUT_MESSAGE_MIDNIGHT : 'Hey %user_name%, the day has finished. Are you still working? :cara_con_monĂ³culo: \nBTW, we just did a clock-out for you; If you want to continue working, please do a new clock-in the Time Tracker app https://timetracker.ioet.com/' + CLOCK_OUT_MESSAGE_MIDNIGHT : 'Hey %user_name%, the day has finished. Are you still working? :face_with_monocle: \nBTW, we just did a clock-out for you. If you want to continue working, please do a new clock-in the Time Tracker app https://timetracker.ioet.com/' }; module.exports = constants; From 6b8c64faa37a91a67dec4489fef37d480a7c9858 Mon Sep 17 00:00:00 2001 From: cxcarvaj Date: Thu, 10 Feb 2022 11:47:06 -0500 Subject: [PATCH 2/4] Fix: time to clock out at midnight --- .../handlers/automatic-clock-outs/clock_out.js | 6 +++--- .../handlers/automatic-clock-outs/constants.js | 4 ++-- .../handlers/automatic-clock-outs/time_entry.js | 16 ++++++++++------ 3 files changed, 15 insertions(+), 11 deletions(-) diff --git a/nodejs-functions/src/handlers/automatic-clock-outs/clock_out.js b/nodejs-functions/src/handlers/automatic-clock-outs/clock_out.js index fd6f64e..4f73494 100644 --- a/nodejs-functions/src/handlers/automatic-clock-outs/clock_out.js +++ b/nodejs-functions/src/handlers/automatic-clock-outs/clock_out.js @@ -46,7 +46,7 @@ const doClockOut = async (context) => { if (userId) { SlackClient.sendMessageToUser(userId, CLOCK_OUT_MESSAGE_MIDNIGHT.replace('%user_name%', userName)); } - timeEntryAsJson.end_date = timeEntry.getTimeToClockOut(); + timeEntryAsJson.end_date = timeEntry.getTimeToClockOutMidnight(); await container.item(timeEntryAsJson.id, timeEntryAsJson.tenant_id).replace(timeEntryAsJson); } }) @@ -62,8 +62,8 @@ const findUserData = (users, id) => { return user ? { userName: user.displayName.split(" ")[0], userEmail: _.first(user.otherMails) } : {}; }; -const findSlackUserId = (users, email) => { - const user = users.find((user) => user.email === email); +const findSlackUserId = (slackUsers, email) => { + const user = slackUsers.find((slackUser) => slackUser.email === email); return user ? user.id : null; }; diff --git a/nodejs-functions/src/handlers/automatic-clock-outs/constants.js b/nodejs-functions/src/handlers/automatic-clock-outs/constants.js index 9f8f20c..0d0b60c 100644 --- a/nodejs-functions/src/handlers/automatic-clock-outs/constants.js +++ b/nodejs-functions/src/handlers/automatic-clock-outs/constants.js @@ -1,6 +1,6 @@ const constants = { - CLOCK_OUT_MESSAGE : 'OMG %user_name%!, you have been working more than 12 hours in a row. \nPlease take a break and visit https://timetracker.ioet.com/ to set the right end time for your entries, we just did a clock out for you :wink:', - CLOCK_OUT_MESSAGE_MIDNIGHT : 'Hey %user_name%, the day has finished. Are you still working? :face_with_monocle: \nBTW, we just did a clock-out for you. If you want to continue working, please do a new clock-in the Time Tracker app https://timetracker.ioet.com/' + CLOCK_OUT_MESSAGE : 'OMG %user_name%!, you have been working more than 12 hours in a row. \nPlease take a break and visit :ioet: to set the right end time for your entries, we just did a clock out for you :wink:', + CLOCK_OUT_MESSAGE_MIDNIGHT : 'Hey %user_name%, the day has finished. Are you still working? :face_with_monocle: \nBTW, we just did a clock-out for you. If you want to continue working, please use :ioet: to clock back in.' }; module.exports = constants; diff --git a/nodejs-functions/src/handlers/automatic-clock-outs/time_entry.js b/nodejs-functions/src/handlers/automatic-clock-outs/time_entry.js index eade4bb..8332872 100644 --- a/nodejs-functions/src/handlers/automatic-clock-outs/time_entry.js +++ b/nodejs-functions/src/handlers/automatic-clock-outs/time_entry.js @@ -16,23 +16,27 @@ class TimeEntry { getMidnightInTimeEntryZone(){ return moment(this.timeEntry.start_date).utc() - .subtract(this.timeEntry.timezone_offset, 'minutes').endOf('day') + .subtract(this.timeEntry.timezone_offset, 'minutes').endOf('day'); + } + + getTimeToClockOutMidnight(){ + return moment().utc().endOf('day').toISOString(); } getCurrentTimeInTimeEntryZone(){ - return moment().utc().subtract(this.timeEntry.timezone_offset, 'minutes') + return moment().utc().subtract(this.timeEntry.timezone_offset, 'minutes'); } needsToBeClockedOut() { - const currentTimeInUTC = moment().utc() - const minutesRunning = moment.duration(currentTimeInUTC.diff(this.getStartTimeInUTC())).asMinutes() + const currentTimeInUTC = moment().utc(); + const minutesRunning = moment.duration(currentTimeInUTC.diff(this.getStartTimeInUTC())).asMinutes(); return minutesRunning > 720; } needsToBeClockedOutMidnight(){ - return this.getMidnightInTimeEntryZone().isBefore(this.getCurrentTimeInTimeEntryZone()) + return this.getMidnightInTimeEntryZone().isBefore(this.getCurrentTimeInTimeEntryZone()); } } -module.exports = TimeEntry +module.exports = TimeEntry; From 77ec46b10935fe38ba9c6508076dccf38b1b591f Mon Sep 17 00:00:00 2001 From: cxcarvaj Date: Fri, 11 Feb 2022 12:28:40 -0500 Subject: [PATCH 3/4] Fix: Time entries offsets --- .../handlers/automatic-clock-outs/clock_out.js | 1 + .../automatic-clock-outs/package-lock.json | 16 ++++++++-------- .../handlers/automatic-clock-outs/package.json | 4 ++-- .../handlers/automatic-clock-outs/time_entry.js | 5 ++--- 4 files changed, 13 insertions(+), 13 deletions(-) diff --git a/nodejs-functions/src/handlers/automatic-clock-outs/clock_out.js b/nodejs-functions/src/handlers/automatic-clock-outs/clock_out.js index 4f73494..8a15406 100644 --- a/nodejs-functions/src/handlers/automatic-clock-outs/clock_out.js +++ b/nodejs-functions/src/handlers/automatic-clock-outs/clock_out.js @@ -48,6 +48,7 @@ const doClockOut = async (context) => { } timeEntryAsJson.end_date = timeEntry.getTimeToClockOutMidnight(); await container.item(timeEntryAsJson.id, timeEntryAsJson.tenant_id).replace(timeEntryAsJson); + totalClockOutsExecuted++; } }) ); diff --git a/nodejs-functions/src/handlers/automatic-clock-outs/package-lock.json b/nodejs-functions/src/handlers/automatic-clock-outs/package-lock.json index 2241937..55bc701 100644 --- a/nodejs-functions/src/handlers/automatic-clock-outs/package-lock.json +++ b/nodejs-functions/src/handlers/automatic-clock-outs/package-lock.json @@ -13,7 +13,7 @@ "@azure/msal-node": "^1.0.0-alpha.5", "@slack/web-api": "^6.0.0", "axios": "^0.20.0", - "dotenv": "^8.2.0", + "dotenv": "^16.0.0", "moment": "^2.27.0", "msal": "^1.4.0" }, @@ -1240,11 +1240,11 @@ } }, "node_modules/dotenv": { - "version": "8.2.0", - "resolved": "https://registry.npmjs.org/dotenv/-/dotenv-8.2.0.tgz", - "integrity": "sha512-8sJ78ElpbDJBHNeBzUbUVLsqKdccaa/BXF1uPTw3GrvQTBgrQrtObr2mUrE38vzYd8cEv+m/JBfDLioYcfXoaw==", + "version": "16.0.0", + "resolved": "https://registry.npmjs.org/dotenv/-/dotenv-16.0.0.tgz", + "integrity": "sha512-qD9WU0MPM4SWLPJy/r2Be+2WgQj8plChsyrCNQzW/0WjvcJQiKQJ9mH3ZgB3fxbUUxgc/11ZJ0Fi5KiimWGz2Q==", "engines": { - "node": ">=8" + "node": ">=12" } }, "node_modules/duplexer3": { @@ -4674,9 +4674,9 @@ } }, "dotenv": { - "version": "8.2.0", - "resolved": "https://registry.npmjs.org/dotenv/-/dotenv-8.2.0.tgz", - "integrity": "sha512-8sJ78ElpbDJBHNeBzUbUVLsqKdccaa/BXF1uPTw3GrvQTBgrQrtObr2mUrE38vzYd8cEv+m/JBfDLioYcfXoaw==" + "version": "16.0.0", + "resolved": "https://registry.npmjs.org/dotenv/-/dotenv-16.0.0.tgz", + "integrity": "sha512-qD9WU0MPM4SWLPJy/r2Be+2WgQj8plChsyrCNQzW/0WjvcJQiKQJ9mH3ZgB3fxbUUxgc/11ZJ0Fi5KiimWGz2Q==" }, "duplexer3": { "version": "0.1.4", diff --git a/nodejs-functions/src/handlers/automatic-clock-outs/package.json b/nodejs-functions/src/handlers/automatic-clock-outs/package.json index ceb28ad..9df20e0 100644 --- a/nodejs-functions/src/handlers/automatic-clock-outs/package.json +++ b/nodejs-functions/src/handlers/automatic-clock-outs/package.json @@ -9,10 +9,10 @@ "dependencies": { "@azure/cosmos": "3.5.2", "@azure/msal-node": "^1.0.0-alpha.5", + "@slack/web-api": "^6.0.0", "axios": "^0.20.0", - "dotenv": "^8.2.0", + "dotenv": "^16.0.0", "moment": "^2.27.0", - "@slack/web-api": "^6.0.0", "msal": "^1.4.0" }, "author": "", diff --git a/nodejs-functions/src/handlers/automatic-clock-outs/time_entry.js b/nodejs-functions/src/handlers/automatic-clock-outs/time_entry.js index 8332872..d3f88ff 100644 --- a/nodejs-functions/src/handlers/automatic-clock-outs/time_entry.js +++ b/nodejs-functions/src/handlers/automatic-clock-outs/time_entry.js @@ -15,12 +15,11 @@ class TimeEntry { } getMidnightInTimeEntryZone(){ - return moment(this.timeEntry.start_date).utc() - .subtract(this.timeEntry.timezone_offset, 'minutes').endOf('day'); + return moment(this.timeEntry.start_date).utcOffset(this.timeEntry.timezone_offset * -1).endOf('day'); } getTimeToClockOutMidnight(){ - return moment().utc().endOf('day').toISOString(); + return moment(this.timeEntry.start_date).utcOffset(this.timeEntry.timezone_offset * -1).endOf('day').toISOString(); } getCurrentTimeInTimeEntryZone(){ From b344194865ae7db16204e61325a606b19060ea4e Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 11 Feb 2022 18:02:08 +0000 Subject: [PATCH 4/4] build(deps): bump axios Bumps [axios](https://github.com/axios/axios) from 0.20.0 to 0.21.2. - [Release notes](https://github.com/axios/axios/releases) - [Changelog](https://github.com/axios/axios/blob/master/CHANGELOG.md) - [Commits](https://github.com/axios/axios/compare/v0.20.0...v0.21.2) --- updated-dependencies: - dependency-name: axios dependency-type: direct:production ... Signed-off-by: dependabot[bot] --- .../automatic-clock-outs/package-lock.json | 54 +++++++------------ .../automatic-clock-outs/package.json | 2 +- 2 files changed, 21 insertions(+), 35 deletions(-) diff --git a/nodejs-functions/src/handlers/automatic-clock-outs/package-lock.json b/nodejs-functions/src/handlers/automatic-clock-outs/package-lock.json index 55bc701..c57e496 100644 --- a/nodejs-functions/src/handlers/automatic-clock-outs/package-lock.json +++ b/nodejs-functions/src/handlers/automatic-clock-outs/package-lock.json @@ -12,7 +12,7 @@ "@azure/cosmos": "3.5.2", "@azure/msal-node": "^1.0.0-alpha.5", "@slack/web-api": "^6.0.0", - "axios": "^0.20.0", + "axios": "^0.21.2", "dotenv": "^16.0.0", "moment": "^2.27.0", "msal": "^1.4.0" @@ -288,14 +288,6 @@ "npm": ">= 6.12.0" } }, - "node_modules/@slack/web-api/node_modules/axios": { - "version": "0.21.1", - "resolved": "https://registry.npmjs.org/axios/-/axios-0.21.1.tgz", - "integrity": "sha512-dKQiRHxGD9PPRIUNIWvZhPTPpl1rf/OxTYKsqKUDjBwYylTvV7SjSHJb9ratfyzM6wCdLCOYLzs73qpg5c4iGA==", - "dependencies": { - "follow-redirects": "^1.10.0" - } - }, "node_modules/@szmarczak/http-timer": { "version": "1.1.2", "resolved": "https://registry.npmjs.org/@szmarczak/http-timer/-/http-timer-1.1.2.tgz", @@ -619,12 +611,11 @@ } }, "node_modules/axios": { - "version": "0.20.0", - "resolved": "https://registry.npmjs.org/axios/-/axios-0.20.0.tgz", - "integrity": "sha512-ANA4rr2BDcmmAQLOKft2fufrtuvlqR+cXNNinUmvfeSNCOF98PZL+7M/v1zIdGo7OLjEA9J2gXJL+j4zGsl0bA==", - "deprecated": "Critical security vulnerability fixed in v0.21.1. For more information, see https://github.com/axios/axios/pull/3410", + "version": "0.21.2", + "resolved": "https://registry.npmjs.org/axios/-/axios-0.21.2.tgz", + "integrity": "sha512-87otirqUw3e8CzHTMO+/9kh/FSgXt/eVDvipijwDtEuwbkySWZ9SBm6VEubmJ/kLKEoLQV/POhxXFb66bfekfg==", "dependencies": { - "follow-redirects": "^1.10.0" + "follow-redirects": "^1.14.0" } }, "node_modules/balanced-match": { @@ -1445,9 +1436,9 @@ } }, "node_modules/follow-redirects": { - "version": "1.13.0", - "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.13.0.tgz", - "integrity": "sha512-aq6gF1BEKje4a9i9+5jimNFIpq4Q1WiwBToeRK5NvZBd/TRsmW8BsJfOEGkr76TbOyPVD3OVDN910EcUNtRYEA==", + "version": "1.14.8", + "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.14.8.tgz", + "integrity": "sha512-1x0S9UVJHsQprFcEC/qnNzBLcIxsjAV905f/UkQxbclCsoTWlacCNOpQa/anodLl2uaEKFhfWOvM2Qg77+15zA==", "funding": [ { "type": "individual", @@ -1456,6 +1447,11 @@ ], "engines": { "node": ">=4.0" + }, + "peerDependenciesMeta": { + "debug": { + "optional": true + } } }, "node_modules/form-data": { @@ -3907,16 +3903,6 @@ "is-stream": "^1.1.0", "p-queue": "^6.6.1", "p-retry": "^4.0.0" - }, - "dependencies": { - "axios": { - "version": "0.21.1", - "resolved": "https://registry.npmjs.org/axios/-/axios-0.21.1.tgz", - "integrity": "sha512-dKQiRHxGD9PPRIUNIWvZhPTPpl1rf/OxTYKsqKUDjBwYylTvV7SjSHJb9ratfyzM6wCdLCOYLzs73qpg5c4iGA==", - "requires": { - "follow-redirects": "^1.10.0" - } - } } }, "@szmarczak/http-timer": { @@ -4184,11 +4170,11 @@ } }, "axios": { - "version": "0.20.0", - "resolved": "https://registry.npmjs.org/axios/-/axios-0.20.0.tgz", - "integrity": "sha512-ANA4rr2BDcmmAQLOKft2fufrtuvlqR+cXNNinUmvfeSNCOF98PZL+7M/v1zIdGo7OLjEA9J2gXJL+j4zGsl0bA==", + "version": "0.21.2", + "resolved": "https://registry.npmjs.org/axios/-/axios-0.21.2.tgz", + "integrity": "sha512-87otirqUw3e8CzHTMO+/9kh/FSgXt/eVDvipijwDtEuwbkySWZ9SBm6VEubmJ/kLKEoLQV/POhxXFb66bfekfg==", "requires": { - "follow-redirects": "^1.10.0" + "follow-redirects": "^1.14.0" } }, "balanced-match": { @@ -4833,9 +4819,9 @@ } }, "follow-redirects": { - "version": "1.13.0", - "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.13.0.tgz", - "integrity": "sha512-aq6gF1BEKje4a9i9+5jimNFIpq4Q1WiwBToeRK5NvZBd/TRsmW8BsJfOEGkr76TbOyPVD3OVDN910EcUNtRYEA==" + "version": "1.14.8", + "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.14.8.tgz", + "integrity": "sha512-1x0S9UVJHsQprFcEC/qnNzBLcIxsjAV905f/UkQxbclCsoTWlacCNOpQa/anodLl2uaEKFhfWOvM2Qg77+15zA==" }, "form-data": { "version": "2.5.1", diff --git a/nodejs-functions/src/handlers/automatic-clock-outs/package.json b/nodejs-functions/src/handlers/automatic-clock-outs/package.json index 9df20e0..550bfab 100644 --- a/nodejs-functions/src/handlers/automatic-clock-outs/package.json +++ b/nodejs-functions/src/handlers/automatic-clock-outs/package.json @@ -10,7 +10,7 @@ "@azure/cosmos": "3.5.2", "@azure/msal-node": "^1.0.0-alpha.5", "@slack/web-api": "^6.0.0", - "axios": "^0.20.0", + "axios": "^0.21.2", "dotenv": "^16.0.0", "moment": "^2.27.0", "msal": "^1.4.0"