Skip to content

Commit 6cfa7d5

Browse files
authored
Merge pull request #76 from ioet/TT-482-receive-a-message-before-midnight
TT - 482 receive a message before midnight
2 parents 6281bfc + 6b8c64f commit 6cfa7d5

File tree

3 files changed

+15
-11
lines changed

3 files changed

+15
-11
lines changed

nodejs-functions/src/handlers/automatic-clock-outs/clock_out.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ const doClockOut = async (context) => {
4646
if (userId) {
4747
SlackClient.sendMessageToUser(userId, CLOCK_OUT_MESSAGE_MIDNIGHT.replace('%user_name%', userName));
4848
}
49-
timeEntryAsJson.end_date = timeEntry.getTimeToClockOut();
49+
timeEntryAsJson.end_date = timeEntry.getTimeToClockOutMidnight();
5050
await container.item(timeEntryAsJson.id, timeEntryAsJson.tenant_id).replace(timeEntryAsJson);
5151
}
5252
})
@@ -62,8 +62,8 @@ const findUserData = (users, id) => {
6262
return user ? { userName: user.displayName.split(" ")[0], userEmail: _.first(user.otherMails) } : {};
6363
};
6464

65-
const findSlackUserId = (users, email) => {
66-
const user = users.find((user) => user.email === email);
65+
const findSlackUserId = (slackUsers, email) => {
66+
const user = slackUsers.find((slackUser) => slackUser.email === email);
6767
return user ? user.id : null;
6868
};
6969

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
const constants = {
2-
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:',
3-
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/'
2+
CLOCK_OUT_MESSAGE : 'OMG %user_name%!, you have been working more than 12 hours in a row. \nPlease take a break and visit :ioet: <https://timetracker.ioet.com|Time Tracker App> to set the right end time for your entries, we just did a clock out for you :wink:',
3+
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: <https://timetracker.ioet.com|Time Tracker App> to clock back in.'
44
};
55

66
module.exports = constants;

nodejs-functions/src/handlers/automatic-clock-outs/time_entry.js

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,23 +16,27 @@ class TimeEntry {
1616

1717
getMidnightInTimeEntryZone(){
1818
return moment(this.timeEntry.start_date).utc()
19-
.subtract(this.timeEntry.timezone_offset, 'minutes').endOf('day')
19+
.subtract(this.timeEntry.timezone_offset, 'minutes').endOf('day');
20+
}
21+
22+
getTimeToClockOutMidnight(){
23+
return moment().utc().endOf('day').toISOString();
2024
}
2125

2226
getCurrentTimeInTimeEntryZone(){
23-
return moment().utc().subtract(this.timeEntry.timezone_offset, 'minutes')
27+
return moment().utc().subtract(this.timeEntry.timezone_offset, 'minutes');
2428
}
2529

2630
needsToBeClockedOut() {
27-
const currentTimeInUTC = moment().utc()
28-
const minutesRunning = moment.duration(currentTimeInUTC.diff(this.getStartTimeInUTC())).asMinutes()
31+
const currentTimeInUTC = moment().utc();
32+
const minutesRunning = moment.duration(currentTimeInUTC.diff(this.getStartTimeInUTC())).asMinutes();
2933
return minutesRunning > 720;
3034
}
3135

3236
needsToBeClockedOutMidnight(){
33-
return this.getMidnightInTimeEntryZone().isBefore(this.getCurrentTimeInTimeEntryZone())
37+
return this.getMidnightInTimeEntryZone().isBefore(this.getCurrentTimeInTimeEntryZone());
3438
}
3539
}
3640

37-
module.exports = TimeEntry
41+
module.exports = TimeEntry;
3842

0 commit comments

Comments
 (0)