@@ -8,7 +8,7 @@ const SlackClient = require('./slack_client');
8
8
const { CLOCK_OUT_MESSAGE , CLOCK_OUT_MESSAGE_MIDNIGHT } = require ( './constants' ) ;
9
9
10
10
const doClockOut = async ( context ) => {
11
- console . log (
11
+ context . log (
12
12
`I am going to check how many entries were not clocked out ${ new Date ( ) } `
13
13
) ;
14
14
@@ -23,52 +23,50 @@ const doClockOut = async (context) => {
23
23
const slackUsers = await SlackClient . findUsersInSlack ( ) ;
24
24
25
25
const { resources : entries } = await timeEntryDao . getEntriesWithNoEndDate ( ) ;
26
- console . log ( `Checking for time-entries that need to be clocked out` ) ;
26
+ context . log ( `Checking for time-entries that need to be clocked out` ) ;
27
27
28
28
let totalClockOutsExecuted = 0 ;
29
29
30
30
await Promise . all (
31
31
entries . map ( async ( timeEntryAsJson ) => {
32
32
const timeEntry = new TimeEntry ( timeEntryAsJson ) ;
33
- const { userName, userEmail } = findUserData ( users , timeEntry . timeEntry . owner_id ) ;
33
+ const { userName, userEmail } = findUserData ( users , timeEntry . timeEntry . owner_id ) ;
34
34
const userId = findSlackUserId ( slackUsers , userEmail ) ;
35
- if ( userEmail === '[email protected] ' ) {
36
- if ( timeEntry . needsToBeClockedOut ( ) ) {
37
- if ( userId ) {
38
- SlackClient . sendMessageToUser ( userId , CLOCK_OUT_MESSAGE . replace ( '%user_name%' , userName ) ) ;
39
- }
40
- timeEntryAsJson . end_date = timeEntry . getTimeToClockOut ( ) ;
41
- await container . item ( timeEntryAsJson . id , timeEntryAsJson . tenant_id ) . replace ( timeEntryAsJson ) ;
42
- totalClockOutsExecuted ++ ;
35
+
36
+ if ( timeEntry . needsToBeClockedOut ( ) ) {
37
+ if ( userId ) {
38
+ SlackClient . sendMessageToUser ( userId , CLOCK_OUT_MESSAGE . replace ( '%user_name%' , userName ) ) ;
43
39
}
44
-
45
- else if ( timeEntry . needsToBeClockedOutMidnight ( ) ) {
46
- if ( userId ) {
47
- SlackClient . sendMessageToUser ( userId , CLOCK_OUT_MESSAGE_MIDNIGHT . replace ( '%user_name%' , userName ) ) ;
48
- }
49
- timeEntryAsJson . end_date = timeEntry . getTimeToClockOutMidnight ( ) ;
50
- await container . item ( timeEntryAsJson . id , timeEntryAsJson . tenant_id ) . replace ( timeEntryAsJson ) ;
51
- totalClockOutsExecuted ++ ;
40
+ timeEntryAsJson . end_date = timeEntry . getTimeToClockOut ( ) ;
41
+ await container . item ( timeEntryAsJson . id , timeEntryAsJson . tenant_id ) . replace ( timeEntryAsJson ) ;
42
+ totalClockOutsExecuted ++ ;
43
+
44
+ } else if ( timeEntry . needsToBeClockedOutMidnight ( ) ) {
45
+ if ( userId ) {
46
+ SlackClient . sendMessageToUser ( userId , CLOCK_OUT_MESSAGE_MIDNIGHT . replace ( '%user_name%' , userName ) ) ;
52
47
}
48
+ timeEntryAsJson . end_date = timeEntry . getTimeToClockOutMidnight ( ) ;
49
+ await container . item ( timeEntryAsJson . id , timeEntryAsJson . tenant_id ) . replace ( timeEntryAsJson ) ;
50
+ totalClockOutsExecuted ++ ;
53
51
}
54
-
55
52
} )
56
53
) ;
57
54
58
- console . log (
55
+ context . log (
59
56
`I just clocked out ${ totalClockOutsExecuted } entries, thanks are not needed...`
60
57
) ;
61
58
} ;
62
59
63
-
64
60
const findUserData = ( users , id ) => {
65
61
const user = users . find ( ( user ) => user . id === id ) ;
66
- return user ? { userName : user . name . split ( ' ' ) [ 0 ] , userEmail : ( user . email ) } : { } ;
62
+ return user
63
+ ? { userName : user . name . split ( ' ' ) [ 0 ] , userEmail : user . email }
64
+ : { } ;
67
65
} ;
68
66
69
67
const findSlackUserId = ( slackUsers , email ) => {
70
68
const user = slackUsers . find ( ( slackUser ) => slackUser . email === email ) ;
71
69
return user ? user . id : null ;
72
70
} ;
73
- doClockOut ( )
71
+
74
72
module . exports = { doClockOut } ;
0 commit comments