Skip to content

Commit 504a0f3

Browse files
committed
Fix: Azure endpoint return all users from ioet
1 parent 67c6f70 commit 504a0f3

File tree

1 file changed

+22
-24
lines changed
  • nodejs-functions/src/handlers/automatic-clock-outs

1 file changed

+22
-24
lines changed

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

Lines changed: 22 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ const SlackClient = require('./slack_client');
88
const { CLOCK_OUT_MESSAGE, CLOCK_OUT_MESSAGE_MIDNIGHT } = require('./constants');
99

1010
const doClockOut = async (context) => {
11-
console.log(
11+
context.log(
1212
`I am going to check how many entries were not clocked out ${new Date()}`
1313
);
1414

@@ -23,52 +23,50 @@ const doClockOut = async (context) => {
2323
const slackUsers = await SlackClient.findUsersInSlack();
2424

2525
const { resources: entries } = await timeEntryDao.getEntriesWithNoEndDate();
26-
console.log(`Checking for time-entries that need to be clocked out`);
26+
context.log(`Checking for time-entries that need to be clocked out`);
2727

2828
let totalClockOutsExecuted = 0;
2929

3030
await Promise.all(
3131
entries.map(async (timeEntryAsJson) => {
3232
const timeEntry = new TimeEntry(timeEntryAsJson);
33-
const { userName, userEmail } = findUserData(users, timeEntry.timeEntry.owner_id);
33+
const { userName, userEmail } = findUserData( users, timeEntry.timeEntry.owner_id);
3434
const userId = findSlackUserId(slackUsers, userEmail);
35-
if( userEmail === '[email protected]'){
36-
if (timeEntry.needsToBeClockedOut()) {
37-
if (userId) {
38-
SlackClient.sendMessageToUser(userId, CLOCK_OUT_MESSAGE.replace('%user_name%', userName));
39-
}
40-
timeEntryAsJson.end_date = timeEntry.getTimeToClockOut();
41-
await container.item(timeEntryAsJson.id, timeEntryAsJson.tenant_id).replace(timeEntryAsJson);
42-
totalClockOutsExecuted++;
35+
36+
if (timeEntry.needsToBeClockedOut()) {
37+
if (userId) {
38+
SlackClient.sendMessageToUser(userId, CLOCK_OUT_MESSAGE.replace('%user_name%', userName));
4339
}
44-
45-
else if (timeEntry.needsToBeClockedOutMidnight()) {
46-
if (userId) {
47-
SlackClient.sendMessageToUser(userId, CLOCK_OUT_MESSAGE_MIDNIGHT.replace('%user_name%', userName));
48-
}
49-
timeEntryAsJson.end_date = timeEntry.getTimeToClockOutMidnight();
50-
await container.item(timeEntryAsJson.id, timeEntryAsJson.tenant_id).replace(timeEntryAsJson);
51-
totalClockOutsExecuted++;
40+
timeEntryAsJson.end_date = timeEntry.getTimeToClockOut();
41+
await container.item(timeEntryAsJson.id, timeEntryAsJson.tenant_id).replace(timeEntryAsJson);
42+
totalClockOutsExecuted++;
43+
44+
} else if (timeEntry.needsToBeClockedOutMidnight()) {
45+
if (userId) {
46+
SlackClient.sendMessageToUser(userId,CLOCK_OUT_MESSAGE_MIDNIGHT.replace('%user_name%', userName));
5247
}
48+
timeEntryAsJson.end_date = timeEntry.getTimeToClockOutMidnight();
49+
await container.item(timeEntryAsJson.id, timeEntryAsJson.tenant_id).replace(timeEntryAsJson);
50+
totalClockOutsExecuted++;
5351
}
54-
5552
})
5653
);
5754

58-
console.log(
55+
context.log(
5956
`I just clocked out ${totalClockOutsExecuted} entries, thanks are not needed...`
6057
);
6158
};
6259

63-
6460
const findUserData = (users, id) => {
6561
const user = users.find((user) => user.id === id);
66-
return user ? { userName: user.name.split(' ')[0], userEmail: (user.email) } : {};
62+
return user
63+
? { userName: user.name.split(' ')[0], userEmail: user.email }
64+
: {};
6765
};
6866

6967
const findSlackUserId = (slackUsers, email) => {
7068
const user = slackUsers.find((slackUser) => slackUser.email === email);
7169
return user ? user.id : null;
7270
};
73-
doClockOut()
71+
7472
module.exports = { doClockOut };

0 commit comments

Comments
 (0)