Skip to content

Commit dbcad2c

Browse files
committed
WIP avoid mentioning same person twice
1 parent be6fe30 commit dbcad2c

File tree

4 files changed

+31
-18
lines changed

4 files changed

+31
-18
lines changed

AutomaticClockOuts/clock_out.js

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,30 +3,30 @@ const config = require("./config");
33
const TimeEntry = require('./time_entry');
44
const axios = require('axios');
55
const 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+
const userToClockOut = findUser(users, timeEntry.timeEntry.owner_id);
27+
if(!userToClockOut.includes(userToClockOut)){
28+
usersWithClockOut.push(userToClockOut)
29+
}
3030
timeEntryAsJson.end_date = timeEntry.getTimeToClockOut()
3131
await container.item(timeEntryAsJson.id, timeEntryAsJson.tenant_id).replace(timeEntryAsJson)
3232
totalClockOutsExecuted++

AutomaticClockOuts/config.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ const config = {
22
endpoint: process.env["ENDPOINT"],
33
key: process.env["KEY"],
44
databaseId: "time-tracker-db",
5-
containerId: "time_entry",
65
partitionKey: { kind: "Hash", paths: ["/category"] },
76
clientId: process.env["CLIENT_ID"],
87
authority: process.env["AUTHORITY"],

AutomaticClockOuts/index.js

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,3 @@
1-
const CosmosClient = require("@azure/cosmos").CosmosClient;
2-
const config = require("./config");
3-
const TimeEntry = require('./time_entry');
4-
const axios = require('axios');
5-
const MsalClient = require('./msal_client');
61
const ClockOut = require('./clock_out');
72

83
module.exports = async function (context, myTimer) {
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
class TimeEntryDao {
2+
3+
CONTAINER_ID = 'time_entry';
4+
5+
constructor(database) {
6+
this.container = database.container(this.CONTAINER_ID);
7+
}
8+
9+
async getEntriesWithNoEndDate () {
10+
const QUERY_WITHOUT_END_DATE =
11+
"SELECT * FROM c WHERE (NOT IS_DEFINED(c.end_date) OR IS_NULL(c.end_date) = true) AND IS_DEFINED(c.start_date)";
12+
return this.container.items
13+
.query({query: QUERY_WITHOUT_END_DATE})
14+
.fetchAll();
15+
}
16+
17+
}
18+
19+
module.exports = TimeEntryDao

0 commit comments

Comments
 (0)