@@ -3,30 +3,27 @@ const config = require("./config");
33const TimeEntry = require ( './time_entry' ) ;
44const axios = require ( 'axios' ) ;
55const MsalClient = require ( './msal_client' )
6+ const TimeEntryDao = require ( './time_entry_dao' )
67
7- const doClockOut = async ( context , timer ) => {
8+ const doClockOut = async ( context ) => {
89 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 ;
1012 const client = new CosmosClient ( { endpoint, key} ) ;
1113 const database = client . database ( databaseId ) ;
12- const container = database . container ( containerId ) ;
14+ const timeEntryDao = new TimeEntryDao ( database ) ;
15+
1316 const response = await MsalClient . findUsersInMS ( ) ;
1417 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 ( ) ;
2319 context . log ( `Checking for time-entries that need to be clocked out` ) ;
20+
2421 let totalClockOutsExecuted = 0 ;
2522 const usersWithClockOut = [ ]
2623 await Promise . all ( entries . map ( async ( timeEntryAsJson ) => {
2724 const timeEntry = new TimeEntry ( timeEntryAsJson )
2825 if ( timeEntry . needsToBeClockedOut ( ) ) {
29- usersWithClockOut . push ( findUser ( users , timeEntry . timeEntry . owner_id ) )
26+ usersWithClockOut . push ( findUser ( users , timeEntry . timeEntry . owner_id ) ) ;
3027 timeEntryAsJson . end_date = timeEntry . getTimeToClockOut ( )
3128 await container . item ( timeEntryAsJson . id , timeEntryAsJson . tenant_id ) . replace ( timeEntryAsJson )
3229 totalClockOutsExecuted ++
0 commit comments