fix(PTO): Fix incorrect module access allowed for PTO GET Totals route

This commit is contained in:
Nic D 2026-03-18 15:43:12 -04:00
parent 9f0ce738c2
commit 8fdc2baf21
4 changed files with 17 additions and 27 deletions

View File

@ -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 { CsvExportService } from "./services/csv-exports.service";
import { ModuleAccessAllowed } from "src/common/decorators/modules-guard.decorators"; import { ModuleAccessAllowed } from "src/common/decorators/modules-guard.decorators";
import { Modules as ModulesEnum } from "prisma/postgres/generated/prisma/client/postgres/client"; 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 { CsvGeneratorService } from "src/time-and-attendance/exports/services/csv-builder.service";
import type { CsvFilters } from "src/time-and-attendance/exports/export-csv-options.dto"; 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('year') year: number,
@Param('period_no') period_no: number, @Param('period_no') period_no: number,
@Body() filters: CsvFilters, @Body() filters: CsvFilters,
// @Res() response: Response,
) { ) {
const rows = await this.csvService.collectTransaction(year, period_no, filters); const rows = await this.csvService.collectTransaction(year, period_no, filters);
const buffer = this.generator.generateCsv(rows); const buffer = this.generator.generateCsv(rows);
@ -28,13 +26,6 @@ export class CsvExportController {
return new StreamableFile(buffer, { return new StreamableFile(buffer, {
type: 'text/csv', type: 'text/csv',
disposition: 'attachment; filename=export.csv' disposition: 'attachment; filename=export.csv'
}) });
// response.set({
// 'Content-Type': 'text/csv',
// 'Content-Disposition': 'attachment; filename="export.csv"',
// });
// response.send(blob);
} }
} }

View File

@ -10,7 +10,7 @@ export class PaidTimeOffController {
) { } ) { }
@Get('totals') @Get('totals')
@ModuleAccessAllowed('timesheets', 'timesheets_approval', 'employee_management') @ModuleAccessAllowed('timesheets')
async getPaidTimeOffTotalsForOneEmployee( async getPaidTimeOffTotalsForOneEmployee(
@Access('email') email: string, @Access('email') email: string,
@Query('email') employee_email?: string, @Query('email') employee_email?: string,

View File

@ -146,13 +146,7 @@ export class GetOverviewService {
switch (type) { switch (type) {
case "EVENING": case "EVENING":
if (total_weekly_hours + hours <= 40) { record.other_hours.evening_hours += Math.min(hours, 8 - daily_hours);
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);
}
total_weekly_hours += hours; total_weekly_hours += hours;
record.total_hours += hours; record.total_hours += hours;
break; break;
@ -169,12 +163,16 @@ export class GetOverviewService {
record.total_hours += hours; record.total_hours += hours;
total_weekly_hours += hours; total_weekly_hours += hours;
break; break;
case "VACATION": record.other_hours.vacation_hours += hours; case "VACATION":
record.other_hours.vacation_hours += hours;
total_weekly_hours += hours;
break; break;
case "REGULAR": case "REGULAR":
if (total_weekly_hours + hours <= 40) { if (total_weekly_hours + hours <= 40) {
record.regular_hours += Math.min(hours, 8 - daily_hours); record.regular_hours += hours;
record.other_hours.overtime_hours += Math.max(daily_hours + hours - 8, 0); // 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 { } else {
record.regular_hours += Math.max(40 - total_weekly_hours, 0); record.regular_hours += Math.max(40 - total_weekly_hours, 0);
record.other_hours.overtime_hours += Math.min(total_weekly_hours + hours - 40, hours); record.other_hours.overtime_hours += Math.min(total_weekly_hours + hours - 40, hours);

View File

@ -82,6 +82,7 @@ export const mapOneTimesheet = (
weekly_hours[subgroup] += hours; weekly_hours[subgroup] += hours;
} }
// TODO: ADD DAILY OVERTIME CHECK HERE
// const dailyOvertimeOwed = Math.max(daily_hours.regular - timesheet.employee.daily_expected_hours, 0) // const dailyOvertimeOwed = Math.max(daily_hours.regular - timesheet.employee.daily_expected_hours, 0)
// daily_hours.overtime = dailyOvertimeOwed; // daily_hours.overtime = dailyOvertimeOwed;
// daily_hours.regular -= dailyOvertimeOwed; // daily_hours.regular -= dailyOvertimeOwed;