File tree Expand file tree Collapse file tree 8 files changed +10
-36
lines changed
nodejs-functions/src/handlers/automatic-clock-outs Expand file tree Collapse file tree 8 files changed +10
-36
lines changed Original file line number Diff line number Diff 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-
6255module . exports = { doClockOut } ;
Original file line number Diff line number Diff 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
1312module . exports = config ;
Original file line number Diff line number Diff line change @@ -38,6 +38,5 @@ CLIENT_ID='XXX'
3838AUTHORITY=' XXX'
3939CLIENT_SECRET=' XXX'
4040SLACK_TOKEN_NOTIFY=' XXX'
41- ID_CHANNEL_NOTIFY=' XXX'
42- ```
41+ ```
4342Check the pinned message in our slack channel to get these values
Original file line number Diff line number Diff line change 11const { WebClient, LogLevel } = require ( "@slack/web-api" ) ;
2- const { slackApiToken, channelId } = require ( "./config" ) ;
2+ const { slackApiToken } = require ( "./config" ) ;
33const client = new WebClient ( slackApiToken , { logLevel : LogLevel . DEBUG } ) ;
44
55const 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 } ;
Original file line number Diff line number Diff 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
Original file line number Diff line number Diff 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
1312module . exports = config ;
Original file line number Diff line number Diff line change @@ -38,6 +38,5 @@ CLIENT_ID='XXX'
3838AUTHORITY=' XXX'
3939CLIENT_SECRET=' XXX'
4040SLACK_TOKEN_NOTIFY=' XXX'
41- ID_CHANNEL_NOTIFY=' XXX'
42- ```
41+ ```
4342Check the pinned message in our slack channel to get these values
Original file line number Diff line number Diff line change 11const { WebClient, LogLevel } = require ( "@slack/web-api" ) ;
2- const { slackApiToken, channelId } = require ( "./config" ) ;
2+ const { slackApiToken } = require ( "./config" ) ;
33const client = new WebClient ( slackApiToken , { logLevel : LogLevel . DEBUG } ) ;
44
55const 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 } ;
You can’t perform that action at this time.
0 commit comments