From efc06b8857fbc0890efa286da8655e5781eacb1f Mon Sep 17 00:00:00 2001 From: Matthieu Haineault Date: Thu, 6 Nov 2025 14:45:16 -0500 Subject: [PATCH] fix(shifts): removed unused overtime calculation and return from create or update shifts --- .../shifts/services/shifts-upsert.service.ts | 21 +++---------------- src/time-and-attendance/utils/type.utils.ts | 2 +- 2 files changed, 4 insertions(+), 19 deletions(-) diff --git a/src/time-and-attendance/time-tracker/shifts/services/shifts-upsert.service.ts b/src/time-and-attendance/time-tracker/shifts/services/shifts-upsert.service.ts index 5008fe9..0968ea0 100644 --- a/src/time-and-attendance/time-tracker/shifts/services/shifts-upsert.service.ts +++ b/src/time-and-attendance/time-tracker/shifts/services/shifts-upsert.service.ts @@ -4,7 +4,6 @@ import { Injectable, BadRequestException, ConflictException, NotFoundException } import { shift_select, timesheet_select } from "src/time-and-attendance/utils/selects.utils"; import { BankCodesResolver } from "src/time-and-attendance/utils/resolve-bank-type-id.utils"; import { EmailToIdResolver } from "src/time-and-attendance/utils/resolve-email-id.utils"; -import { OvertimeService } from "src/time-and-attendance/domains/services/overtime.service"; import { PrismaService } from "src/prisma/prisma.service"; import { GetShiftDto } from "src/time-and-attendance/time-tracker/shifts/dtos/shift-get.dto"; import { ShiftEntity } from "src/time-and-attendance/time-tracker/shifts/dtos/shift-payload.dto"; @@ -15,7 +14,6 @@ import { response } from "express"; export class ShiftsUpsertService { constructor( private readonly prisma: PrismaService, - private readonly overtime: OvertimeService, private readonly emailResolver: EmailToIdResolver, private readonly typeResolver: BankCodesResolver, ) { } @@ -27,7 +25,6 @@ export class ShiftsUpsertService { //loads all shifts from a selected day to check for overlaping shifts //checks for overlaping shifts //create new shifts - //calculate overtime async createShifts(email: string, dtos: ShiftDto[]): Promise { if (!Array.isArray(dtos) || dtos.length === 0) return []; @@ -217,7 +214,6 @@ export class ShiftsUpsertService { const { type: bank_type } = await this.typeResolver.findTypeByBankCodeId(row.bank_code_id); - const summary = await this.overtime.getWeekOvertimeSummary(timesheet_id, normed.date, tx); const shift: GetShiftDto = { shift_id: row.id, @@ -230,7 +226,7 @@ export class ShiftsUpsertService { is_approved: false, comment: row.comment ?? undefined, }; - results[index] = { ok: true, data: { shift, overtime: summary } }; + results[index] = { ok: true, data: { shift } }; } return results; @@ -247,7 +243,6 @@ export class ShiftsUpsertService { // check for overlaping possibility // buil a set of data to manipulate modified data only // update shifts in DB - // recalculate overtime after update // return an updated version to display async updateShifts(dtos: ShiftDto[]): Promise { if (!Array.isArray(dtos) || dtos.length === 0) throw new BadRequestException({ error_code: 'SHIFT_MISSING' }); @@ -414,10 +409,6 @@ export class ShiftsUpsertService { data, select: shift_select, }); - const summary_new = await this.overtime.getWeekOvertimeSummary(row.timesheet_id, planned.exist_shift.date, tx); - if (row.date.getTime() !== planned.exist_shift.date.getTime()) { - await this.overtime.getWeekOvertimeSummary(row.timesheet_id, row.date, tx); - } const type = await this.typeResolver.findTypeByBankCodeId(row.bank_code_id); @@ -433,7 +424,7 @@ export class ShiftsUpsertService { comment: row.comment ?? undefined, }; - results.push({ ok: true, id: planned.exist_shift.id, data: { shift: dto, overtime: summary_new } }); + results.push({ ok: true, id: planned.exist_shift.id, data: { shift: dto } }); } catch (error) { throw new BadRequestException('INVALID_SHIFT'); } @@ -446,7 +437,6 @@ export class ShiftsUpsertService { // DELETE //_________________________________________________________________ //finds shifts using shit_ids - //recalc overtime shifts after delete //blocs deletion if approved async deleteShift(shift_id: number) { return await this.prisma.$transaction(async (tx) => { @@ -457,12 +447,7 @@ export class ShiftsUpsertService { if (!shift) throw new ConflictException({ error_code: 'SHIFT_INVALID' }); await tx.shifts.delete({ where: { id: shift_id } }); - - const summary = await this.overtime.getWeekOvertimeSummary(shift.timesheet_id, shift.date, tx); - return { - success: true, - overtime: summary - }; + return { success: true }; }); } diff --git a/src/time-and-attendance/utils/type.utils.ts b/src/time-and-attendance/utils/type.utils.ts index 4088444..4f8ccdc 100644 --- a/src/time-and-attendance/utils/type.utils.ts +++ b/src/time-and-attendance/utils/type.utils.ts @@ -29,7 +29,7 @@ export type Normalized = { date: Date; start_time: Date; end_time: Date; bank_co export type ShiftWithOvertimeDto = { shift: GetShiftDto; - overtime: WeekOvertimeSummary; + // overtime: WeekOvertimeSummary; }; export type CreateShiftResult = { ok: true; data: ShiftWithOvertimeDto } | { ok: false; error: any };