@@ -3,30 +3,27 @@ const config = require("./config");
3
3
const TimeEntry = require ( './time_entry' ) ;
4
4
const axios = require ( 'axios' ) ;
5
5
const MsalClient = require ( './msal_client' )
6
+ const TimeEntryDao = require ( './time_entry_dao' )
6
7
7
- const doClockOut = async ( context , timer ) => {
8
+ const doClockOut = async ( context ) => {
8
9
context . log ( `I am going to check how many entries were not clocked out ${ new Date ( ) } ` ) ;
9
- const { endpoint, key, databaseId, containerId, slackWebHook} = config ;
10
+
11
+ const { endpoint, key, databaseId, slackWebHook } = config ;
10
12
const client = new CosmosClient ( { endpoint, key} ) ;
11
13
const database = client . database ( databaseId ) ;
12
- const container = database . container ( containerId ) ;
14
+ const timeEntryDao = new TimeEntryDao ( database ) ;
15
+
13
16
const response = await MsalClient . findUsersInMS ( ) ;
14
17
const users = response . data . value ;
15
-
16
- const QUERY_WITHOUT_END_DATE =
17
- "SELECT * FROM c WHERE (NOT IS_DEFINED(c.end_date) OR IS_NULL(c.end_date) = true) AND IS_DEFINED(c.start_date)"
18
-
19
- const { resources : entries } = await container . items
20
- . query ( { query : QUERY_WITHOUT_END_DATE } )
21
- . fetchAll ( ) ;
22
-
18
+ const { resources : entries } = await timeEntryDao . getEntriesWithNoEndDate ( ) ;
23
19
context . log ( `Checking for time-entries that need to be clocked out` ) ;
20
+
24
21
let totalClockOutsExecuted = 0 ;
25
22
const usersWithClockOut = [ ]
26
23
await Promise . all ( entries . map ( async ( timeEntryAsJson ) => {
27
24
const timeEntry = new TimeEntry ( timeEntryAsJson )
28
25
if ( timeEntry . needsToBeClockedOut ( ) ) {
29
- usersWithClockOut . push ( findUser ( users , timeEntry . timeEntry . owner_id ) )
26
+ usersWithClockOut . push ( findUser ( users , timeEntry . timeEntry . owner_id ) ) ;
30
27
timeEntryAsJson . end_date = timeEntry . getTimeToClockOut ( )
31
28
await container . item ( timeEntryAsJson . id , timeEntryAsJson . tenant_id ) . replace ( timeEntryAsJson )
32
29
totalClockOutsExecuted ++
0 commit comments