Skip to content

Commit 04b3f4e

Browse files
committed
feat: TT-184 add spaces, move channel id to -env
1 parent fe03475 commit 04b3f4e

File tree

8 files changed

+22
-24
lines changed

8 files changed

+22
-24
lines changed

AutomaticClockOuts/clock_out.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@ const TimeEntry = require('./time_entry');
55
const MsalClient = require('./msal_client');
66
const TimeEntryDao = require('./time_entry_dao');
77
const SlackClient = require('./slack_client');
8-
const { ClockOutMessage } = require('./constants');
8+
const { CLOCK_OUT_MESSAGE } = require('./constants');
99

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

1313
const { endpoint, key, databaseId } = config;
14-
const client = new CosmosClient({endpoint, key});
14+
const client = new CosmosClient({ endpoint, key});
1515
const database = client.database(databaseId);
1616
const container = database.container('time_entry');
1717
const timeEntryDao = new TimeEntryDao(database);
@@ -33,15 +33,15 @@ const doClockOut = async (context) => {
3333
const userId = findSlackUserId(slackUsers, user_email);
3434
if(userId){
3535
usersWithClockOut.push("<@"+userId+">");
36-
SlackClient.sendMessageToUser(userId, ClockOutMessage);
36+
SlackClient.sendMessageToUser(userId, CLOCK_OUT_MESSAGE);
3737
}
3838
timeEntryAsJson.end_date = timeEntry.getTimeToClockOut()
3939
await container.item(timeEntryAsJson.id, timeEntryAsJson.tenant_id).replace(timeEntryAsJson)
4040
totalClockOutsExecuted++
4141
}
4242
}));
4343
if (usersWithClockOut.length) {
44-
const ClockOutMessageChannel=`${ClockOutMessage} \n- ${usersWithClockOut.join('\n- ')}`;
44+
const ClockOutMessageChannel=`${CLOCK_OUT_MESSAGE} \n- ${usersWithClockOut.join('\n- ')}`;
4545
SlackClient.sendMessageToChannel(ClockOutMessageChannel);
4646
}
4747
context.log(`I just clocked out ${totalClockOutsExecuted} entries, thanks are not needed...`);
@@ -52,9 +52,9 @@ const findUserEmail = (users, id) => {
5252
return _.first(user.otherMails)
5353
}
5454

55-
const findSlackUserId = (users,email)=>{
55+
const findSlackUserId = (users, email) => {
5656
const user = users.find(user => user.email === email);
57-
return user? user.id:null
57+
return user ? user.id : null
5858
}
5959

60-
module.exports = {doClockOut};
60+
module.exports = { doClockOut };

AutomaticClockOuts/config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ const config = {
77
authority: process.env["AUTHORITY"],
88
clientSecret: process.env["CLIENT_SECRET"],
99
slackApiToken: process.env["SLACK_TOKEN_NOTIFY"],
10+
channelId: process.env["ID_CHANNEL_NOTIFY"]
1011
};
1112

1213
module.exports = config;

AutomaticClockOuts/constants.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
const constants = {
2-
ClockOutMessage : 'OMG, you have been working more than 12 hours in a row. \nPlease take a break and visit https://timetracker.ioet.com/ to set the right end time for your entries, we just did a clock out for you :wink:',
3-
time_tracker_channel: 'C01694949JR'
2+
CLOCK_OUT_MESSAGE : 'OMG, you have been working more than 12 hours in a row. \nPlease take a break and visit https://timetracker.ioet.com/ to set the right end time for your entries, we just did a clock out for you :wink:'
43
};
54

65
module.exports = constants;

AutomaticClockOuts/slack_client.js

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

65
const findUsersInSlack = async () => {
@@ -26,7 +25,7 @@ const sendMessageToUser = (userId, message) => {
2625

2726
// message to public channel
2827
const sendMessageToChannel = (message) => {
29-
sendMessage(time_tracker_channel, message);
28+
sendMessage(channelId, message);
3029
};
3130

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

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@ const TimeEntry = require('./time_entry');
55
const MsalClient = require('./msal_client');
66
const TimeEntryDao = require('./time_entry_dao');
77
const SlackClient = require('./slack_client');
8-
const { ClockOutMessage } = require('./constants');
8+
const { CLOCK_OUT_MESSAGE } = require('./constants');
99

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

1313
const { endpoint, key, databaseId } = config;
14-
const client = new CosmosClient({endpoint, key});
14+
const client = new CosmosClient({ endpoint, key});
1515
const database = client.database(databaseId);
1616
const container = database.container('time_entry');
1717
const timeEntryDao = new TimeEntryDao(database);
@@ -33,15 +33,15 @@ const doClockOut = async (context) => {
3333
const userId = findSlackUserId(slackUsers, user_email);
3434
if(userId){
3535
usersWithClockOut.push("<@"+userId+">");
36-
SlackClient.sendMessageToUser(userId, ClockOutMessage);
36+
SlackClient.sendMessageToUser(userId, CLOCK_OUT_MESSAGE);
3737
}
3838
timeEntryAsJson.end_date = timeEntry.getTimeToClockOut()
3939
await container.item(timeEntryAsJson.id, timeEntryAsJson.tenant_id).replace(timeEntryAsJson)
4040
totalClockOutsExecuted++
4141
}
4242
}));
4343
if (usersWithClockOut.length) {
44-
const ClockOutMessageChannel=`${ClockOutMessage} \n- ${usersWithClockOut.join('\n- ')}`;
44+
const ClockOutMessageChannel=`${CLOCK_OUT_MESSAGE} \n- ${usersWithClockOut.join('\n- ')}`;
4545
SlackClient.sendMessageToChannel(ClockOutMessageChannel);
4646
}
4747
context.log(`I just clocked out ${totalClockOutsExecuted} entries, thanks are not needed...`);
@@ -52,9 +52,9 @@ const findUserEmail = (users, id) => {
5252
return _.first(user.otherMails)
5353
}
5454

55-
const findSlackUserId = (users,email)=>{
55+
const findSlackUserId = (users, email) => {
5656
const user = users.find(user => user.email === email);
57-
return user? user.id:null
57+
return user ? user.id : null
5858
}
5959

60-
module.exports = {doClockOut};
60+
module.exports = { doClockOut };

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ const config = {
77
authority: process.env["AUTHORITY"],
88
clientSecret: process.env["CLIENT_SECRET"],
99
slackApiToken: process.env["SLACK_TOKEN_NOTIFY"],
10+
channelId: process.env["ID_CHANNEL_NOTIFY"]
1011
};
1112

1213
module.exports = config;
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
const constants = {
2-
ClockOutMessage : 'OMG, you have been working more than 12 hours in a row. \nPlease take a break and visit https://timetracker.ioet.com/ to set the right end time for your entries, we just did a clock out for you :wink:',
3-
time_tracker_channel: 'C01694949JR'
2+
CLOCK_OUT_MESSAGE : 'OMG, you have been working more than 12 hours in a row. \nPlease take a break and visit https://timetracker.ioet.com/ to set the right end time for your entries, we just did a clock out for you :wink:'
43
};
54

65
module.exports = constants;

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

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

65
const findUsersInSlack = async () => {
@@ -26,7 +25,7 @@ const sendMessageToUser = (userId, message) => {
2625

2726
// message to public channel
2827
const sendMessageToChannel = (message) => {
29-
sendMessage(time_tracker_channel, message);
28+
sendMessage(channelId, message);
3029
};
3130

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

0 commit comments

Comments
 (0)