|
1 | 1 | const CosmosClient = require("@azure/cosmos").CosmosClient;
|
2 |
| -const moment = require("moment") |
3 | 2 | const config = require("./config");
|
4 | 3 | const TimeEntry = require('./time_entry');
|
| 4 | +const axios = require('axios'); |
| 5 | +const MsalClient = require('./msal_client'); |
| 6 | +const ClockOut = require('./clock_out'); |
5 | 7 |
|
6 | 8 | module.exports = async function (context, myTimer) {
|
7 |
| - |
8 |
| - context.log(`I am going to check how many entries were not clocked out ${new Date()}`); |
9 |
| - const {endpoint, key, databaseId, containerId} = config; |
10 |
| - const client = new CosmosClient({endpoint, key}); |
11 |
| - const database = client.database(databaseId); |
12 |
| - const container = database.container(containerId); |
13 |
| - |
14 |
| - const QUERY_WITHOUT_END_DATE = |
15 |
| - "SELECT * FROM c WHERE (NOT IS_DEFINED(c.end_date) OR IS_NULL(c.end_date) = true) AND IS_DEFINED(c.start_date)" |
16 |
| - |
17 |
| - const {resources: entries} = await container.items |
18 |
| - .query({query: QUERY_WITHOUT_END_DATE}) |
19 |
| - .fetchAll(); |
20 |
| - |
21 |
| - context.log(`Checking for time-entries that need to be clocked out`); |
22 |
| - let totalClockOutsExecuted = 0; |
23 |
| - await Promise.all(entries.map(async (timeEntryAsJson) => { |
24 |
| - const timeEntry = new TimeEntry(timeEntryAsJson) |
25 |
| - if (timeEntry.needsToBeClockedOut()) { |
26 |
| - context.log(`I am going to clock out ${JSON.stringify(timeEntryAsJson.id)}`); |
27 |
| - timeEntryAsJson.end_date = timeEntry.getTimeToClockOut() |
28 |
| - await container.item(timeEntryAsJson.id, timeEntryAsJson.tenant_id).replace(timeEntryAsJson) |
29 |
| - totalClockOutsExecuted++ |
30 |
| - } |
31 |
| - })); |
32 |
| - context.log(`I just clocked out ${totalClockOutsExecuted} entries, thanks are not needed...`); |
| 9 | + context.log('starting.....................') |
| 10 | + await ClockOut.doClockOut(context, myTimer) |
| 11 | + // context.log(`I am going to check how many entries were not clocked out ${new Date()}`); |
| 12 | + // const {endpoint, key, databaseId, containerId, azureEndpoint} = config; |
| 13 | + // const client = new CosmosClient({endpoint, key}); |
| 14 | + // const database = client.database(databaseId); |
| 15 | + // const container = database.container(containerId); |
| 16 | + // const users = await MsalClient.findUsersInMS(); |
| 17 | + // |
| 18 | + // const QUERY_WITHOUT_END_DATE = |
| 19 | + // "SELECT * FROM c WHERE (NOT IS_DEFINED(c.end_date) OR IS_NULL(c.end_date) = true) AND IS_DEFINED(c.start_date)" |
| 20 | + // |
| 21 | + // const {resources: entries} = await container.items |
| 22 | + // .query({query: QUERY_WITHOUT_END_DATE}) |
| 23 | + // .fetchAll(); |
| 24 | + // |
| 25 | + // context.log(`Checking for time-entries that need to be clocked out`); |
| 26 | + // let totalClockOutsExecuted = 0; |
| 27 | + // await Promise.all(entries.map(async (timeEntryAsJson) => { |
| 28 | + // const timeEntry = new TimeEntry(timeEntryAsJson) |
| 29 | + // if (timeEntry.needsToBeClockedOut()) { |
| 30 | + // context.log(`I am going to clock out ${JSON.stringify(timeEntryAsJson)}`); |
| 31 | + // timeEntryAsJson.end_date = timeEntry.getTimeToClockOut() |
| 32 | + // axios.post('https://hooks.slack.com/services/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', |
| 33 | + // {"text": `Hey, we clocked-out for you yesterday at midnight, please make sure to update your entered data`} |
| 34 | + // ) |
| 35 | + // .then(function (response) { |
| 36 | + // console.log(response); |
| 37 | + // }) |
| 38 | + // .catch(function (error) { |
| 39 | + // console.log(error); |
| 40 | + // }); |
| 41 | + // totalClockOutsExecuted++ |
| 42 | + // } |
| 43 | + // })); |
| 44 | + // context.log(`I just clocked out ${totalClockOutsExecuted} entries, thanks are not needed...`); |
33 | 45 | };
|
0 commit comments