fix(PTO): Fix incorrect module access allowed for PTO GET Totals route
This commit is contained in:
parent
9f0ce738c2
commit
8fdc2baf21
|
|
@ -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);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -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,
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,7 @@ export class GetOverviewService {
|
||||||
) { }
|
) { }
|
||||||
|
|
||||||
async getOverviewByYearPeriod(
|
async getOverviewByYearPeriod(
|
||||||
pay_year: number,
|
pay_year: number,
|
||||||
period_no: number
|
period_no: number
|
||||||
): Promise<Result<PayPeriodOverviewDto, string>> {
|
): Promise<Result<PayPeriodOverviewDto, string>> {
|
||||||
const period = computePeriod(pay_year, period_no);
|
const period = computePeriod(pay_year, period_no);
|
||||||
|
|
@ -110,9 +110,9 @@ export class GetOverviewService {
|
||||||
}
|
}
|
||||||
|
|
||||||
const ensure = (
|
const ensure = (
|
||||||
id: number,
|
id: number,
|
||||||
first_name: string,
|
first_name: string,
|
||||||
last_name: string,
|
last_name: string,
|
||||||
email: string
|
email: string
|
||||||
) => {
|
) => {
|
||||||
if (!by_employee.has(id)) {
|
if (!by_employee.has(id)) {
|
||||||
|
|
@ -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);
|
||||||
|
|
@ -213,7 +211,7 @@ export class GetOverviewService {
|
||||||
|
|
||||||
if (timesheets.length > 0)
|
if (timesheets.length > 0)
|
||||||
record.is_approved = timesheets.every(timesheet => timesheet.is_approved);
|
record.is_approved = timesheets.every(timesheet => timesheet.is_approved);
|
||||||
|
|
||||||
record.is_active = is_active;
|
record.is_active = is_active;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -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;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user