Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
9 changes: 1 addition & 8 deletions AutomaticClockOuts/clock_out.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,26 +24,21 @@ const doClockOut = async (context) => {
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()) {
const user_email = findUserEmail(users, timeEntry.timeEntry.owner_id);
const userId = findSlackUserId(slackUsers, user_email);
if(userId){
usersWithClockOut.push("<@"+userId+">");
SlackClient.sendMessageToUser(userId, CLOCK_OUT_MESSAGE);
}
timeEntryAsJson.end_date = timeEntry.getTimeToClockOut()
await container.item(timeEntryAsJson.id, timeEntryAsJson.tenant_id).replace(timeEntryAsJson)
totalClockOutsExecuted++
}
}));
if (usersWithClockOut.length) {
const ClockOutMessageChannel=`${CLOCK_OUT_MESSAGE} \n- ${usersWithClockOut.join('\n- ')}`;
SlackClient.sendMessageToChannel(ClockOutMessageChannel);
}

context.log(`I just clocked out ${totalClockOutsExecuted} entries, thanks are not needed...`);
}

Expand All @@ -57,6 +52,4 @@ const findSlackUserId = (users, email) => {
return user ? user.id : null
}

doClockOut(console)

module.exports = { doClockOut };
3 changes: 1 addition & 2 deletions AutomaticClockOuts/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ const config = {
clientId: process.env["CLIENT_ID"],
authority: process.env["AUTHORITY"],
clientSecret: process.env["CLIENT_SECRET"],
slackApiToken: process.env["SLACK_TOKEN_NOTIFY"],
channelId: process.env["ID_CHANNEL_NOTIFY"]
slackApiToken: process.env["SLACK_TOKEN_NOTIFY"]
};

module.exports = config;
3 changes: 1 addition & 2 deletions AutomaticClockOuts/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,5 @@ CLIENT_ID='XXX'
AUTHORITY='XXX'
CLIENT_SECRET='XXX'
SLACK_TOKEN_NOTIFY='XXX'
ID_CHANNEL_NOTIFY='XXX'
```
```
Check the pinned message in our slack channel to get these values
9 changes: 2 additions & 7 deletions AutomaticClockOuts/slack_client.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const { WebClient, LogLevel } = require("@slack/web-api");
const { slackApiToken, channelId } = require("./config");
const { slackApiToken } = require("./config");
const client = new WebClient(slackApiToken, { logLevel: LogLevel.DEBUG });

const findUsersInSlack = async () => {
Expand All @@ -23,9 +23,4 @@ const sendMessageToUser = (userId, message) => {
sendMessage(userId, message);
};

// message to public channel
const sendMessageToChannel = (message) => {
sendMessage(channelId, message);
};

module.exports = { findUsersInSlack, sendMessageToUser, sendMessageToChannel };
module.exports = { findUsersInSlack, sendMessageToUser };
Original file line number Diff line number Diff line change
Expand Up @@ -24,26 +24,21 @@ const doClockOut = async (context) => {
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()) {
const user_email = findUserEmail(users, timeEntry.timeEntry.owner_id);
const userId = findSlackUserId(slackUsers, user_email);
if(userId){
usersWithClockOut.push("<@"+userId+">");
SlackClient.sendMessageToUser(userId, CLOCK_OUT_MESSAGE);
}
timeEntryAsJson.end_date = timeEntry.getTimeToClockOut()
await container.item(timeEntryAsJson.id, timeEntryAsJson.tenant_id).replace(timeEntryAsJson)
totalClockOutsExecuted++
}
}));
if (usersWithClockOut.length) {
const ClockOutMessageChannel=`${CLOCK_OUT_MESSAGE} \n- ${usersWithClockOut.join('\n- ')}`;
SlackClient.sendMessageToChannel(ClockOutMessageChannel);
}

context.log(`I just clocked out ${totalClockOutsExecuted} entries, thanks are not needed...`);
}

Expand Down
3 changes: 1 addition & 2 deletions nodejs-functions/src/handlers/automatic-clock-outs/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ const config = {
clientId: process.env["CLIENT_ID"],
authority: process.env["AUTHORITY"],
clientSecret: process.env["CLIENT_SECRET"],
slackApiToken: process.env["SLACK_TOKEN_NOTIFY"],
channelId: process.env["ID_CHANNEL_NOTIFY"]
slackApiToken: process.env["SLACK_TOKEN_NOTIFY"]
};

module.exports = config;
3 changes: 1 addition & 2 deletions nodejs-functions/src/handlers/automatic-clock-outs/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,5 @@ CLIENT_ID='XXX'
AUTHORITY='XXX'
CLIENT_SECRET='XXX'
SLACK_TOKEN_NOTIFY='XXX'
ID_CHANNEL_NOTIFY='XXX'
```
```
Check the pinned message in our slack channel to get these values
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const { WebClient, LogLevel } = require("@slack/web-api");
const { slackApiToken, channelId } = require("./config");
const { slackApiToken } = require("./config");
const client = new WebClient(slackApiToken, { logLevel: LogLevel.DEBUG });

const findUsersInSlack = async () => {
Expand All @@ -23,9 +23,4 @@ const sendMessageToUser = (userId, message) => {
sendMessage(userId, message);
};

// message to public channel
const sendMessageToChannel = (message) => {
sendMessage(channelId, message);
};

module.exports = { findUsersInSlack, sendMessageToUser, sendMessageToChannel };
module.exports = { findUsersInSlack, sendMessageToUser };