-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add total hours sheet tracking for signing out and amending hours
- Loading branch information
Showing
9 changed files
with
97 additions
and
105 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,37 @@ | ||
import Session from "../../models/Session.model"; | ||
import User from "../../models/User.model"; | ||
import { readCell } from "../../spreadsheet"; | ||
import { readCell, writeCell } from "../../spreadsheet"; | ||
import { Cell } from "../../spreadsheet/cell"; | ||
import { RangeNotFound } from "../errors"; | ||
import { getUserRowFromTotalHoursSheet, getUserRowFromHoursHistorySheet } from "./helpers/get-user-row"; | ||
import { msTimesToHourDuration } from "./helpers/times-to-duration"; | ||
|
||
// Add session time to spreadsheet | ||
async function addSingleSession(user: User, session: Session): Promise<void> { | ||
async function addSingleSessionToSpreadsheet(user: User, session: Session): Promise<void> { | ||
// No spreadsheets while testing | ||
if (process.env.NODE_ENV === "testing") { | ||
return; | ||
} | ||
|
||
const totalHoursSheetRow = await getUserRowFromTotalHoursSheet(user); | ||
const hoursHistorySheetRow = await getUserRowFromHoursHistorySheet(user); | ||
const cell = new Cell(process.env.TOTAL_HOURS_SHEET_HOURS_COLUMN, totalHoursSheetRow); | ||
|
||
const hoursCellData = await readCell(process.env.HOURS_SPREADSHEET_ID, process.env.TOTAL_HOURS_SHEET_ID, new Cell(process.env.TOTAL_HOURS_SHEET_HOURS_COLUMN, totalHoursSheetRow)); | ||
let totalHours = isFinite(parseFloat(hoursCellData)) ? parseFloat(hoursCellData) : 0; // If is not finite, then set to 0 TODO: have it check the hours logged in database | ||
let hoursCellData; | ||
try { | ||
hoursCellData = await readCell(process.env.HOURS_SPREADSHEET_ID, process.env.TOTAL_HOURS_SHEET_ID, cell); | ||
} catch (e) { | ||
if (e instanceof RangeNotFound) { | ||
hoursCellData = ""; | ||
} else { | ||
throw e; | ||
} | ||
} | ||
|
||
let totalHours = isFinite(parseFloat(hoursCellData)) ? parseFloat(hoursCellData) : 0; // If is not finite, then set to 0 TODO: have it check the hours logged in database | ||
totalHours += msTimesToHourDuration(session.start_time, session.end_time); | ||
await writeCell(process.env.HOURS_SPREADSHEET_ID, process.env.TOTAL_HOURS_SHEET_ID, cell, totalHours); | ||
// TODO: total hours calculation | ||
} | ||
|
||
export { addSingleSession } | ||
export { addSingleSessionToSpreadsheet }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
export { addSingleSession } from "./add-single-session"; | ||
export { addSingleSessionToSpreadsheet } from "./add-single-session"; |