Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
send slack message on clock out
  • Loading branch information
enriquezrene committed Sep 22, 2020
commit e1a6813f9aab638d8adf24f3e208be78984c7c9d
31 changes: 18 additions & 13 deletions AutomaticClockOuts/clock_out.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,30 +22,35 @@ const doClockOut = async (context, timer) => {

context.log(`Checking for time-entries that need to be clocked out`);
let totalClockOutsExecuted = 0;
const usersWithClockOut = []
await Promise.all(entries.map(async (timeEntryAsJson) => {
const timeEntry = new TimeEntry(timeEntryAsJson)
if (timeEntry.needsToBeClockedOut()) {
context.log(`I am going to clock out ${JSON.stringify(timeEntryAsJson)}`);
usersWithClockOut.push(findUser(users, timeEntry.timeEntry.owner_id))
timeEntryAsJson.end_date = timeEntry.getTimeToClockOut()
console.log(`I am doing it for you ${JSON.stringify(findUser(users, timeEntry.owner_id))}`)
axios.post(process.env["SLACK_WEBHOOK"],
{"text": `I am doing it for you ${JSON.stringify(findUser(users, timeEntry.owner_id))}`}
)
.then(function (response) {
console.log(response);
})
.catch(function (error) {
console.log(error);
});
console.log(JSON.stringify(timeEntry))
await container.item(timeEntryAsJson.id, timeEntryAsJson.tenant_id).replace(timeEntryAsJson)
totalClockOutsExecuted++
}
}));
if(totalClockOutsExecuted > 0){
axios.post(process.env["SLACK_WEBHOOK"],
{
"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- ')}`
}
)
.then(function (response) {
// console.log(response);
})
.catch(function (error) {
context.log(error);
});
}
context.log(`I just clocked out ${totalClockOutsExecuted} entries, thanks are not needed...`);
}

const findUser = (users, id) => {
return users.find( user => user.objectId === id)
const user = users.find( user => user.objectId === id)
return user.displayName
}

module.exports = { doClockOut };
35 changes: 0 additions & 35 deletions AutomaticClockOuts/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,40 +6,5 @@ const MsalClient = require('./msal_client');
const ClockOut = require('./clock_out');

module.exports = async function (context, myTimer) {
context.log('starting.....................')
await ClockOut.doClockOut(context, myTimer)
// context.log(`I am going to check how many entries were not clocked out ${new Date()}`);
// const {endpoint, key, databaseId, containerId, azureEndpoint} = config;
// const client = new CosmosClient({endpoint, key});
// const database = client.database(databaseId);
// const container = database.container(containerId);
// const users = await MsalClient.findUsersInMS();
//
// const QUERY_WITHOUT_END_DATE =
// "SELECT * FROM c WHERE (NOT IS_DEFINED(c.end_date) OR IS_NULL(c.end_date) = true) AND IS_DEFINED(c.start_date)"
//
// const {resources: entries} = await container.items
// .query({query: QUERY_WITHOUT_END_DATE})
// .fetchAll();
//
// context.log(`Checking for time-entries that need to be clocked out`);
// let totalClockOutsExecuted = 0;
// await Promise.all(entries.map(async (timeEntryAsJson) => {
// const timeEntry = new TimeEntry(timeEntryAsJson)
// if (timeEntry.needsToBeClockedOut()) {
// context.log(`I am going to clock out ${JSON.stringify(timeEntryAsJson)}`);
// timeEntryAsJson.end_date = timeEntry.getTimeToClockOut()
// axios.post('https://hooks.slack.com/services/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',
// {"text": `Hey, we clocked-out for you yesterday at midnight, please make sure to update your entered data`}
// )
// .then(function (response) {
// console.log(response);
// })
// .catch(function (error) {
// console.log(error);
// });
// totalClockOutsExecuted++
// }
// }));
// context.log(`I just clocked out ${totalClockOutsExecuted} entries, thanks are not needed...`);
};