From 119116e11dc49d2f08a03829d179273d585e2c2d Mon Sep 17 00:00:00 2001 From: Matthieu Haineault Date: Wed, 15 Oct 2025 14:00:28 -0400 Subject: [PATCH] feat(timesheets): preparing for Express Session requests --- .../services/overtime.service.ts | 2 +- src/modules/shifts/helpers/shifts.helpers.ts | 2 +- src/modules/timesheets/dtos/timesheet.dto.ts | 52 +++++++++++++++++++ .../services/timesheets-command.service.ts | 39 ++++++++++++++ 4 files changed, 93 insertions(+), 2 deletions(-) create mode 100644 src/modules/timesheets/dtos/timesheet.dto.ts diff --git a/src/modules/business-logics/services/overtime.service.ts b/src/modules/business-logics/services/overtime.service.ts index 6c6d1b0..24c7a75 100644 --- a/src/modules/business-logics/services/overtime.service.ts +++ b/src/modules/business-logics/services/overtime.service.ts @@ -14,7 +14,7 @@ export class OvertimeService { constructor(private prisma: PrismaService) {} //calculate daily overtime - async getDailyOvertimeHoursForDay(employee_id: number, date: Date): Promise { + async getDailyOvertimeHours(employee_id: number, date: Date): Promise { const shifts = await this.prisma.shifts.findMany({ where: { date: date, timesheet: { employee_id: employee_id } }, select: { start_time: true, end_time: true }, diff --git a/src/modules/shifts/helpers/shifts.helpers.ts b/src/modules/shifts/helpers/shifts.helpers.ts index 09a17e1..6fb216d 100644 --- a/src/modules/shifts/helpers/shifts.helpers.ts +++ b/src/modules/shifts/helpers/shifts.helpers.ts @@ -114,7 +114,7 @@ export class ShiftsHelpersService { async afterWriteOvertimeAndLog(tx: Tx, employee_id: number, date_only: Date) { // Switch regular → weekly overtime si > 40h await this.overtimeService.transformRegularHoursToWeeklyOvertime(employee_id, date_only, tx); - const daily = await this.overtimeService.getDailyOvertimeHoursForDay(employee_id, date_only); + const daily = await this.overtimeService.getDailyOvertimeHours(employee_id, date_only); const weekly = await this.overtimeService.getWeeklyOvertimeHours(employee_id, date_only); // const [daily, weekly] = await Promise.all([ // this.overtimeService.getDailyOvertimeHoursForDay(employee_id, date_only), diff --git a/src/modules/timesheets/dtos/timesheet.dto.ts b/src/modules/timesheets/dtos/timesheet.dto.ts new file mode 100644 index 0000000..22cd1ae --- /dev/null +++ b/src/modules/timesheets/dtos/timesheet.dto.ts @@ -0,0 +1,52 @@ +export class Timesheets { + timesheet_id: number; + days: TimesheetDay[]; + weekly_hours: TotalHours[]; + weekly_expenses: TotalExpenses[]; +} + +export class TimesheetDay { + date: string; + shifts: Shift[]; + expenses: Expense[]; + daily_hours: TotalHours[]; + daily_expenses: TotalExpenses[]; +} + +export class TotalHours { + regular: number; + evening: number; + emergency: number; + overtime: number; + vacation: number; + holiday: number; + sick: number; +} +export class TotalExpenses { + expenses: number; + perd_diem: number; + on_call: number; + mileage: number; +} + +export class Shift { + date: string; + start: string; + end: string; + type: string; + is_remote: boolean; + is_approved: boolean; + shift_id?: number | null; + comment?: string | null; +} + +export class Expense { + date: string; + is_approved: boolean; + comment: string; + amount?: number; + mileage?: number; + attachment?: string; + expense_id?: number | null; + supervisor_comment?: string | null; +} \ No newline at end of file diff --git a/src/modules/timesheets/services/timesheets-command.service.ts b/src/modules/timesheets/services/timesheets-command.service.ts index f8142b0..179a21a 100644 --- a/src/modules/timesheets/services/timesheets-command.service.ts +++ b/src/modules/timesheets/services/timesheets-command.service.ts @@ -10,6 +10,7 @@ import { EmailToIdResolver } from "src/modules/shared/utils/resolve-email-id.uti import { BankCodesResolver } from "src/modules/shared/utils/resolve-bank-type-id.utils"; import { PrismaService } from "src/prisma/prisma.service"; import { TimesheetMap } from "../utils-helpers-others/timesheet.types"; +import { Shift, Expense } from "../dtos/timesheet.dto"; @Injectable() export class TimesheetsCommandService extends BaseApprovalService{ @@ -50,6 +51,44 @@ export class TimesheetsCommandService extends BaseApprovalService{ return timesheet; } +/**_____________________________________________________________________________________________ + create/update/delete shifts and expenses from 1 or many timesheet(s) + + -this function receives an email and an array of timesheets + + -this function will find the timesheets with all shifts and expenses + -this function will calculate total hours, total expenses, filtered by types, + cumulate in daily and weekly. + + -the timesheet_id will be determined using the employee email + -with the timesheet_id, all shifts and expenses will be fetched + + -with shift_id and expense_id, this function will compare both + datas from the DB and from the body of the function and then: + -it will create a shift if no shift is found in the DB + -it will update a shift if a shift is found in the DB + -it will delete a shift if a shift is found and no data is received from the frontend + + This function will be used for the Timesheet Page for an employee to enter, modify or delete and entry + This function will also be used in the modal of the timesheet validation page to + allow a supervisor to enter, modify or delete and entry of a selected employee +_____________________________________________________________________________________________*/ + +async findTimesheetsByEmailAndPayPeriod(email: string, year: number, period_no: number, timesheets: Timesheets[]): Promise { + const employee_id = await this.emailResolver.findIdByEmail(email); + + + return timesheets; +} + +async upsertOrDeleteShiftsByEmailAndDate(email:string, shift_ids: Shift[]) {} + +async upsertOrDeleteExpensesByEmailAndDate(email:string, expenses_id: Expense[]) {} + + + + + //_____________________________________________________________________________________________ // //_____________________________________________________________________________________________