From 8fdc2baf217904fd10617c94570166cdda0eaf0f Mon Sep 17 00:00:00 2001 From: Nic D Date: Wed, 18 Mar 2026 15:43:12 -0400 Subject: [PATCH] fix(PTO): Fix incorrect module access allowed for PTO GET Totals route --- .../exports/csv-exports.controller.ts | 13 ++------- .../paid-time-off/paid-time-off.controller.ts | 2 +- .../pay-periods-build-overview.service.ts | 28 +++++++++---------- .../timesheets/timesheet.mapper.ts | 1 + 4 files changed, 17 insertions(+), 27 deletions(-) diff --git a/src/time-and-attendance/exports/csv-exports.controller.ts b/src/time-and-attendance/exports/csv-exports.controller.ts index 5b95a37..288a58d 100644 --- a/src/time-and-attendance/exports/csv-exports.controller.ts +++ b/src/time-and-attendance/exports/csv-exports.controller.ts @@ -1,8 +1,7 @@ -import { Body, Controller, Param, Post, Res, StreamableFile } from "@nestjs/common"; +import { Body, Controller, Param, Post, StreamableFile } from "@nestjs/common"; import { CsvExportService } from "./services/csv-exports.service"; import { ModuleAccessAllowed } from "src/common/decorators/modules-guard.decorators"; import { Modules as ModulesEnum } from "prisma/postgres/generated/prisma/client/postgres/client"; -// import { Response } from "express"; import { CsvGeneratorService } from "src/time-and-attendance/exports/services/csv-builder.service"; import type { CsvFilters } from "src/time-and-attendance/exports/export-csv-options.dto"; @@ -20,7 +19,6 @@ export class CsvExportController { @Param('year') year: number, @Param('period_no') period_no: number, @Body() filters: CsvFilters, - // @Res() response: Response, ) { const rows = await this.csvService.collectTransaction(year, period_no, filters); const buffer = this.generator.generateCsv(rows); @@ -28,13 +26,6 @@ export class CsvExportController { return new StreamableFile(buffer, { type: 'text/csv', disposition: 'attachment; filename=export.csv' - }) - - // response.set({ - // 'Content-Type': 'text/csv', - // 'Content-Disposition': 'attachment; filename="export.csv"', - // }); - - // response.send(blob); + }); } } \ No newline at end of file diff --git a/src/time-and-attendance/paid-time-off/paid-time-off.controller.ts b/src/time-and-attendance/paid-time-off/paid-time-off.controller.ts index d1fc8e3..1a14de5 100644 --- a/src/time-and-attendance/paid-time-off/paid-time-off.controller.ts +++ b/src/time-and-attendance/paid-time-off/paid-time-off.controller.ts @@ -10,7 +10,7 @@ export class PaidTimeOffController { ) { } @Get('totals') - @ModuleAccessAllowed('timesheets', 'timesheets_approval', 'employee_management') + @ModuleAccessAllowed('timesheets') async getPaidTimeOffTotalsForOneEmployee( @Access('email') email: string, @Query('email') employee_email?: string, diff --git a/src/time-and-attendance/pay-period/services/pay-periods-build-overview.service.ts b/src/time-and-attendance/pay-period/services/pay-periods-build-overview.service.ts index 7c7eca4..0542d1a 100644 --- a/src/time-and-attendance/pay-period/services/pay-periods-build-overview.service.ts +++ b/src/time-and-attendance/pay-period/services/pay-periods-build-overview.service.ts @@ -12,7 +12,7 @@ export class GetOverviewService { ) { } async getOverviewByYearPeriod( - pay_year: number, + pay_year: number, period_no: number ): Promise> { const period = computePeriod(pay_year, period_no); @@ -110,9 +110,9 @@ export class GetOverviewService { } const ensure = ( - id: number, - first_name: string, - last_name: string, + id: number, + first_name: string, + last_name: string, email: string ) => { if (!by_employee.has(id)) { @@ -146,13 +146,7 @@ export class GetOverviewService { switch (type) { case "EVENING": - if (total_weekly_hours + hours <= 40) { - record.other_hours.evening_hours += Math.min(hours, 8 - daily_hours); - record.other_hours.overtime_hours += Math.max(daily_hours + hours - 8, 0); - } else { - record.other_hours.evening_hours += Math.max(40 - total_weekly_hours, 0); - record.other_hours.overtime_hours += Math.min(total_weekly_hours + hours - 40, hours); - } + record.other_hours.evening_hours += Math.min(hours, 8 - daily_hours); total_weekly_hours += hours; record.total_hours += hours; break; @@ -169,12 +163,16 @@ export class GetOverviewService { record.total_hours += hours; total_weekly_hours += hours; break; - case "VACATION": record.other_hours.vacation_hours += hours; + case "VACATION": + record.other_hours.vacation_hours += hours; + total_weekly_hours += hours; break; case "REGULAR": if (total_weekly_hours + hours <= 40) { - record.regular_hours += Math.min(hours, 8 - daily_hours); - record.other_hours.overtime_hours += Math.max(daily_hours + hours - 8, 0); + record.regular_hours += hours; + // TODO: ADD DAILY OVERTIME CHECK HERE + // record.regular_hours += Math.min(hours, 8 - daily_hours); + // record.other_hours.overtime_hours += Math.max(daily_hours + hours - 8, 0); } else { record.regular_hours += Math.max(40 - total_weekly_hours, 0); record.other_hours.overtime_hours += Math.min(total_weekly_hours + hours - 40, hours); @@ -213,7 +211,7 @@ export class GetOverviewService { if (timesheets.length > 0) record.is_approved = timesheets.every(timesheet => timesheet.is_approved); - + record.is_active = is_active; } diff --git a/src/time-and-attendance/timesheets/timesheet.mapper.ts b/src/time-and-attendance/timesheets/timesheet.mapper.ts index 0a117ac..5e55be9 100644 --- a/src/time-and-attendance/timesheets/timesheet.mapper.ts +++ b/src/time-and-attendance/timesheets/timesheet.mapper.ts @@ -82,6 +82,7 @@ export const mapOneTimesheet = ( weekly_hours[subgroup] += hours; } + // TODO: ADD DAILY OVERTIME CHECK HERE // const dailyOvertimeOwed = Math.max(daily_hours.regular - timesheet.employee.daily_expected_hours, 0) // daily_hours.overtime = dailyOvertimeOwed; // daily_hours.regular -= dailyOvertimeOwed;