Skip to content

Commit 85d709f

Browse files
authored
Merge pull request #11 from ioet/10-avoid-mentioning-same-person-twice
closes #10 avoid mentioning same person twice
2 parents be6fe30 + b8be91c commit 85d709f

File tree

5 files changed

+33
-22
lines changed

5 files changed

+33
-22
lines changed

AutomaticClockOuts/clock_out.js

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,30 +3,27 @@ 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+
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++

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) {

AutomaticClockOuts/readme.md

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,11 @@ NOTE:
3232
Don't forget to set the following environment variables to make this app work:
3333

3434
```sh
35-
COSMOS_DB_KEY
36-
MS_CLIENT_ID
37-
MS_AUTHORITY
38-
MS_CLIENT_SECRET
35+
ENDPOINT='XXX'
36+
KEY='XXX'
37+
CLIENT_ID='XXX'
38+
AUTHORITY='XXX'
39+
CLIENT_SECRET='XXX'
40+
SLACK_WEBHOOK='XXX'
3941
```
4042
Check the pinned message in our slack channel to get these values
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
class TimeEntryDao {
2+
3+
constructor(database) {
4+
const CONTAINER_ID = 'time_entry';
5+
this.container = database.container(CONTAINER_ID);
6+
}
7+
8+
async getEntriesWithNoEndDate () {
9+
const QUERY_WITHOUT_END_DATE =
10+
"SELECT * FROM c WHERE (NOT IS_DEFINED(c.end_date) OR IS_NULL(c.end_date) = true) AND IS_DEFINED(c.start_date) AND (NOT IS_DEFINED(c.deleted) OR IS_NULL(c.deleted) = true)";
11+
return this.container.items
12+
.query({query: QUERY_WITHOUT_END_DATE})
13+
.fetchAll();
14+
}
15+
16+
}
17+
18+
module.exports = TimeEntryDao

0 commit comments

Comments
 (0)