Skip to content

Commit e1a6813

Browse files
committed
send slack message on clock out
1 parent 3b4754b commit e1a6813

File tree

2 files changed

+18
-48
lines changed

2 files changed

+18
-48
lines changed

AutomaticClockOuts/clock_out.js

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -22,30 +22,35 @@ const doClockOut = async (context, timer) => {
2222

2323
context.log(`Checking for time-entries that need to be clocked out`);
2424
let totalClockOutsExecuted = 0;
25+
const usersWithClockOut = []
2526
await Promise.all(entries.map(async (timeEntryAsJson) => {
2627
const timeEntry = new TimeEntry(timeEntryAsJson)
2728
if (timeEntry.needsToBeClockedOut()) {
28-
context.log(`I am going to clock out ${JSON.stringify(timeEntryAsJson)}`);
29+
usersWithClockOut.push(findUser(users, timeEntry.timeEntry.owner_id))
2930
timeEntryAsJson.end_date = timeEntry.getTimeToClockOut()
30-
console.log(`I am doing it for you ${JSON.stringify(findUser(users, timeEntry.owner_id))}`)
31-
axios.post(process.env["SLACK_WEBHOOK"],
32-
{"text": `I am doing it for you ${JSON.stringify(findUser(users, timeEntry.owner_id))}`}
33-
)
34-
.then(function (response) {
35-
console.log(response);
36-
})
37-
.catch(function (error) {
38-
console.log(error);
39-
});
40-
console.log(JSON.stringify(timeEntry))
31+
await container.item(timeEntryAsJson.id, timeEntryAsJson.tenant_id).replace(timeEntryAsJson)
4132
totalClockOutsExecuted++
4233
}
4334
}));
35+
if(totalClockOutsExecuted > 0){
36+
axios.post(process.env["SLACK_WEBHOOK"],
37+
{
38+
"text": `Hey guys, I did a clock out for you. \nVisit https://timetracker.ioet.com/ and set the right end time for your entries :pls: \n- ${usersWithClockOut.join('\n- ')}`
39+
}
40+
)
41+
.then(function (response) {
42+
// console.log(response);
43+
})
44+
.catch(function (error) {
45+
context.log(error);
46+
});
47+
}
4448
context.log(`I just clocked out ${totalClockOutsExecuted} entries, thanks are not needed...`);
4549
}
4650

4751
const findUser = (users, id) => {
48-
return users.find( user => user.objectId === id)
52+
const user = users.find( user => user.objectId === id)
53+
return user.displayName
4954
}
5055

5156
module.exports = { doClockOut };

AutomaticClockOuts/index.js

Lines changed: 0 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -6,40 +6,5 @@ const MsalClient = require('./msal_client');
66
const ClockOut = require('./clock_out');
77

88
module.exports = async function (context, myTimer) {
9-
context.log('starting.....................')
109
await ClockOut.doClockOut(context, myTimer)
11-
// context.log(`I am going to check how many entries were not clocked out ${new Date()}`);
12-
// const {endpoint, key, databaseId, containerId, azureEndpoint} = config;
13-
// const client = new CosmosClient({endpoint, key});
14-
// const database = client.database(databaseId);
15-
// const container = database.container(containerId);
16-
// const users = await MsalClient.findUsersInMS();
17-
//
18-
// const QUERY_WITHOUT_END_DATE =
19-
// "SELECT * FROM c WHERE (NOT IS_DEFINED(c.end_date) OR IS_NULL(c.end_date) = true) AND IS_DEFINED(c.start_date)"
20-
//
21-
// const {resources: entries} = await container.items
22-
// .query({query: QUERY_WITHOUT_END_DATE})
23-
// .fetchAll();
24-
//
25-
// context.log(`Checking for time-entries that need to be clocked out`);
26-
// let totalClockOutsExecuted = 0;
27-
// await Promise.all(entries.map(async (timeEntryAsJson) => {
28-
// const timeEntry = new TimeEntry(timeEntryAsJson)
29-
// if (timeEntry.needsToBeClockedOut()) {
30-
// context.log(`I am going to clock out ${JSON.stringify(timeEntryAsJson)}`);
31-
// timeEntryAsJson.end_date = timeEntry.getTimeToClockOut()
32-
// axios.post('https://hooks.slack.com/services/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',
33-
// {"text": `Hey, we clocked-out for you yesterday at midnight, please make sure to update your entered data`}
34-
// )
35-
// .then(function (response) {
36-
// console.log(response);
37-
// })
38-
// .catch(function (error) {
39-
// console.log(error);
40-
// });
41-
// totalClockOutsExecuted++
42-
// }
43-
// }));
44-
// context.log(`I just clocked out ${totalClockOutsExecuted} entries, thanks are not needed...`);
4510
};

0 commit comments

Comments
 (0)