Skip to content

Commit

Permalink
Layout for hours history logging for spreadsheet
Browse files Browse the repository at this point in the history
  • Loading branch information
Cow-Van committed May 12, 2024
1 parent b9b665c commit 8d0441c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 15 deletions.
11 changes: 2 additions & 9 deletions src/spreadsheet/index.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,2 @@
import { readCell, readCellRange } from "./read";
import { writeCell, writeCellRange } from "./write";

export {
readCell,
readCellRange,
writeCell,
writeCellRange,
}
export { readCell, readCellRange } from "./read";
export { writeCell, writeCellRange } from "./write";
22 changes: 16 additions & 6 deletions src/utils/spreadsheet-hours/add-single-session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,12 @@ async function addSingleSessionToSpreadsheet(user: User, session: Session): Prom
return;
}

const totalHoursSheetRow = await getUserRowFromTotalHoursSheet(user);
const hoursHistorySheetRow = await getUserRowFromHoursHistorySheet(user);
const cell = new Cell(process.env.TOTAL_HOURS_SHEET_HOURS_COLUMN, totalHoursSheetRow);
const totalHoursSheetRow = await getUserRowFromTotalHoursSheet(user); // TODO: If row does not exists throw error
const totalHoursCell = new Cell(process.env.TOTAL_HOURS_SHEET_HOURS_COLUMN, totalHoursSheetRow);

let hoursCellData;
try {
hoursCellData = await readCell(process.env.HOURS_SPREADSHEET_ID, process.env.TOTAL_HOURS_SHEET_ID, cell);
hoursCellData = await readCell(process.env.HOURS_SPREADSHEET_ID, process.env.TOTAL_HOURS_SHEET_ID, totalHoursCell);
} catch (e) {
if (e instanceof RangeNotFound) {
hoursCellData = "";
Expand All @@ -30,8 +29,19 @@ async function addSingleSessionToSpreadsheet(user: User, session: Session): Prom

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
await writeCell(process.env.HOURS_SPREADSHEET_ID, process.env.TOTAL_HOURS_SHEET_ID, totalHoursCell, totalHours);

// TODO: hours history calculation
const hoursHistorySheetRow = await getUserRowFromHoursHistorySheet(user);
// IF user's row does not exist, append at bottom
// Add name to header columns

// IF current date column does not exist, append at the right
// Add date to header row
// ELSE get existing cell data from user's row and current date column intersection
// Add new session time to existing cell data time

// Overwrite existing cell data
}

export { addSingleSessionToSpreadsheet };

0 comments on commit 8d0441c

Please sign in to comment.