Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
WIP avoid mentioning same person twice
  • Loading branch information
enriquezrene committed Nov 20, 2020
commit dbcad2c838944841b7df870713752ce4068ea2d4
24 changes: 12 additions & 12 deletions AutomaticClockOuts/clock_out.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,30 +3,30 @@ const config = require("./config");
const TimeEntry = require('./time_entry');
const axios = require('axios');
const MsalClient = require('./msal_client')
const TimeEntryDao = require('./time_entry_dao')

const doClockOut = async (context, timer) => {
const doClockOut = async (context) => {
context.log(`I am going to check how many entries were not clocked out ${new Date()}`);
const {endpoint, key, databaseId, containerId, slackWebHook} = config;

const { endpoint, key, databaseId, slackWebHook } = config;
const client = new CosmosClient({endpoint, key});
const database = client.database(databaseId);
const container = database.container(containerId);
const timeEntryDao = new TimeEntryDao(database);

const response = await MsalClient.findUsersInMS();
const users = response.data.value;

const QUERY_WITHOUT_END_DATE =
"SELECT * FROM c WHERE (NOT IS_DEFINED(c.end_date) OR IS_NULL(c.end_date) = true) AND IS_DEFINED(c.start_date)"

const {resources: entries} = await container.items
.query({query: QUERY_WITHOUT_END_DATE})
.fetchAll();

const {resources: entries} = await timeEntryDao.getEntriesWithNoEndDate();
context.log(`Checking for time-entries that need to be clocked out`);

let totalClockOutsExecuted = 0;
const usersWithClockOut = []
await Promise.all(entries.map(async (timeEntryAsJson) => {
const timeEntry = new TimeEntry(timeEntryAsJson)
if (timeEntry.needsToBeClockedOut()) {
usersWithClockOut.push(findUser(users, timeEntry.timeEntry.owner_id))
const userToClockOut = findUser(users, timeEntry.timeEntry.owner_id);
if(!userToClockOut.includes(userToClockOut)){
usersWithClockOut.push(userToClockOut)
}
timeEntryAsJson.end_date = timeEntry.getTimeToClockOut()
await container.item(timeEntryAsJson.id, timeEntryAsJson.tenant_id).replace(timeEntryAsJson)
totalClockOutsExecuted++
Expand Down
1 change: 0 additions & 1 deletion AutomaticClockOuts/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ const config = {
endpoint: process.env["ENDPOINT"],
key: process.env["KEY"],
databaseId: "time-tracker-db",
containerId: "time_entry",
partitionKey: { kind: "Hash", paths: ["/category"] },
clientId: process.env["CLIENT_ID"],
authority: process.env["AUTHORITY"],
Expand Down
5 changes: 0 additions & 5 deletions AutomaticClockOuts/index.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
const CosmosClient = require("@azure/cosmos").CosmosClient;
const config = require("./config");
const TimeEntry = require('./time_entry');
const axios = require('axios');
const MsalClient = require('./msal_client');
const ClockOut = require('./clock_out');

module.exports = async function (context, myTimer) {
Expand Down
19 changes: 19 additions & 0 deletions AutomaticClockOuts/time_entry_dao.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
class TimeEntryDao {

CONTAINER_ID = 'time_entry';

constructor(database) {
this.container = database.container(this.CONTAINER_ID);
}

async getEntriesWithNoEndDate () {
const QUERY_WITHOUT_END_DATE =
"SELECT * FROM c WHERE (NOT IS_DEFINED(c.end_date) OR IS_NULL(c.end_date) = true) AND IS_DEFINED(c.start_date)";
return this.container.items
.query({query: QUERY_WITHOUT_END_DATE})
.fetchAll();
}

}

module.exports = TimeEntryDao