Skip to content

Commit 9380312

Browse files
authored
refactor: TT-198 Remove public notifications in the channel slack: #ioet-time-tracker (#45)
1 parent 6bbfc1b commit 9380312

File tree

8 files changed

+10
-36
lines changed

8 files changed

+10
-36
lines changed

AutomaticClockOuts/clock_out.js

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,26 +24,21 @@ const doClockOut = async (context) => {
2424
context.log(`Checking for time-entries that need to be clocked out`);
2525

2626
let totalClockOutsExecuted = 0;
27-
const usersWithClockOut = [];
2827

2928
await Promise.all(entries.map(async (timeEntryAsJson) => {
3029
const timeEntry = new TimeEntry(timeEntryAsJson)
3130
if (timeEntry.needsToBeClockedOut()) {
3231
const user_email = findUserEmail(users, timeEntry.timeEntry.owner_id);
3332
const userId = findSlackUserId(slackUsers, user_email);
3433
if(userId){
35-
usersWithClockOut.push("<@"+userId+">");
3634
SlackClient.sendMessageToUser(userId, CLOCK_OUT_MESSAGE);
3735
}
3836
timeEntryAsJson.end_date = timeEntry.getTimeToClockOut()
3937
await container.item(timeEntryAsJson.id, timeEntryAsJson.tenant_id).replace(timeEntryAsJson)
4038
totalClockOutsExecuted++
4139
}
4240
}));
43-
if (usersWithClockOut.length) {
44-
const ClockOutMessageChannel=`${CLOCK_OUT_MESSAGE} \n- ${usersWithClockOut.join('\n- ')}`;
45-
SlackClient.sendMessageToChannel(ClockOutMessageChannel);
46-
}
41+
4742
context.log(`I just clocked out ${totalClockOutsExecuted} entries, thanks are not needed...`);
4843
}
4944

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

60-
doClockOut(console)
61-
6255
module.exports = { doClockOut };

AutomaticClockOuts/config.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@ const config = {
66
clientId: process.env["CLIENT_ID"],
77
authority: process.env["AUTHORITY"],
88
clientSecret: process.env["CLIENT_SECRET"],
9-
slackApiToken: process.env["SLACK_TOKEN_NOTIFY"],
10-
channelId: process.env["ID_CHANNEL_NOTIFY"]
9+
slackApiToken: process.env["SLACK_TOKEN_NOTIFY"]
1110
};
1211

1312
module.exports = config;

AutomaticClockOuts/readme.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,5 @@ CLIENT_ID='XXX'
3838
AUTHORITY='XXX'
3939
CLIENT_SECRET='XXX'
4040
SLACK_TOKEN_NOTIFY='XXX'
41-
ID_CHANNEL_NOTIFY='XXX'
42-
```
41+
```
4342
Check the pinned message in our slack channel to get these values

AutomaticClockOuts/slack_client.js

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
const { WebClient, LogLevel } = require("@slack/web-api");
2-
const { slackApiToken, channelId } = require("./config");
2+
const { slackApiToken } = require("./config");
33
const client = new WebClient(slackApiToken, { logLevel: LogLevel.DEBUG });
44

55
const findUsersInSlack = async () => {
@@ -23,9 +23,4 @@ const sendMessageToUser = (userId, message) => {
2323
sendMessage(userId, message);
2424
};
2525

26-
// message to public channel
27-
const sendMessageToChannel = (message) => {
28-
sendMessage(channelId, message);
29-
};
30-
31-
module.exports = { findUsersInSlack, sendMessageToUser, sendMessageToChannel };
26+
module.exports = { findUsersInSlack, sendMessageToUser };

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

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,26 +24,21 @@ const doClockOut = async (context) => {
2424
context.log(`Checking for time-entries that need to be clocked out`);
2525

2626
let totalClockOutsExecuted = 0;
27-
const usersWithClockOut = [];
2827

2928
await Promise.all(entries.map(async (timeEntryAsJson) => {
3029
const timeEntry = new TimeEntry(timeEntryAsJson)
3130
if (timeEntry.needsToBeClockedOut()) {
3231
const user_email = findUserEmail(users, timeEntry.timeEntry.owner_id);
3332
const userId = findSlackUserId(slackUsers, user_email);
3433
if(userId){
35-
usersWithClockOut.push("<@"+userId+">");
3634
SlackClient.sendMessageToUser(userId, CLOCK_OUT_MESSAGE);
3735
}
3836
timeEntryAsJson.end_date = timeEntry.getTimeToClockOut()
3937
await container.item(timeEntryAsJson.id, timeEntryAsJson.tenant_id).replace(timeEntryAsJson)
4038
totalClockOutsExecuted++
4139
}
4240
}));
43-
if (usersWithClockOut.length) {
44-
const ClockOutMessageChannel=`${CLOCK_OUT_MESSAGE} \n- ${usersWithClockOut.join('\n- ')}`;
45-
SlackClient.sendMessageToChannel(ClockOutMessageChannel);
46-
}
41+
4742
context.log(`I just clocked out ${totalClockOutsExecuted} entries, thanks are not needed...`);
4843
}
4944

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@ const config = {
66
clientId: process.env["CLIENT_ID"],
77
authority: process.env["AUTHORITY"],
88
clientSecret: process.env["CLIENT_SECRET"],
9-
slackApiToken: process.env["SLACK_TOKEN_NOTIFY"],
10-
channelId: process.env["ID_CHANNEL_NOTIFY"]
9+
slackApiToken: process.env["SLACK_TOKEN_NOTIFY"]
1110
};
1211

1312
module.exports = config;

nodejs-functions/src/handlers/automatic-clock-outs/readme.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,5 @@ CLIENT_ID='XXX'
3838
AUTHORITY='XXX'
3939
CLIENT_SECRET='XXX'
4040
SLACK_TOKEN_NOTIFY='XXX'
41-
ID_CHANNEL_NOTIFY='XXX'
42-
```
41+
```
4342
Check the pinned message in our slack channel to get these values

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

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
const { WebClient, LogLevel } = require("@slack/web-api");
2-
const { slackApiToken, channelId } = require("./config");
2+
const { slackApiToken } = require("./config");
33
const client = new WebClient(slackApiToken, { logLevel: LogLevel.DEBUG });
44

55
const findUsersInSlack = async () => {
@@ -23,9 +23,4 @@ const sendMessageToUser = (userId, message) => {
2323
sendMessage(userId, message);
2424
};
2525

26-
// message to public channel
27-
const sendMessageToChannel = (message) => {
28-
sendMessage(channelId, message);
29-
};
30-
31-
module.exports = { findUsersInSlack, sendMessageToUser, sendMessageToChannel };
26+
module.exports = { findUsersInSlack, sendMessageToUser };

0 commit comments

Comments
 (0)