fix(timesheet): removed magic number

This commit is contained in:
Matthieu Haineault 2025-08-18 10:57:35 -04:00
parent 30f7179fe6
commit 4d2ed4714f

View File

@ -8,6 +8,8 @@ import { computeHours } from 'src/common/utils/date-utils';
import { buildPrismaWhere } from 'src/common/shared/build-prisma-where'; import { buildPrismaWhere } from 'src/common/shared/build-prisma-where';
import { SearchTimesheetDto } from '../dtos/search-timesheet.dto'; import { SearchTimesheetDto } from '../dtos/search-timesheet.dto';
const ROUND_TO = 5;
@Injectable() @Injectable()
export class TimesheetsQueryService { export class TimesheetsQueryService {
constructor( constructor(
@ -15,6 +17,8 @@ export class TimesheetsQueryService {
private readonly overtime: OvertimeService, private readonly overtime: OvertimeService,
) {} ) {}
async create(dto : CreateTimesheetDto): Promise<Timesheets> { async create(dto : CreateTimesheetDto): Promise<Timesheets> {
const { employee_id, is_approved } = dto; const { employee_id, is_approved } = dto;
return this.prisma.timesheets.create({ return this.prisma.timesheets.create({
@ -42,7 +46,7 @@ export class TimesheetsQueryService {
rawlist.map(async timesheet => { rawlist.map(async timesheet => {
//detailed shifts //detailed shifts
const detailedShifts = timesheet.shift.map(shift => { const detailedShifts = timesheet.shift.map(shift => {
const totalhours = computeHours(shift.start_time, shift.end_time,5); const totalhours = computeHours(shift.start_time, shift.end_time, ROUND_TO);
const regularHours = Math.min(8, totalhours); const regularHours = Math.min(8, totalhours);
const dailyOvertime = this.overtime.getDailyOvertimeHours(shift.start_time, shift.end_time); const dailyOvertime = this.overtime.getDailyOvertimeHours(shift.start_time, shift.end_time);
const payRegular = regularHours * shift.bank_code.modifier; const payRegular = regularHours * shift.bank_code.modifier;