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 1a104c1..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? :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 : '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;