fix(shifts): removed unused overtime calculation and return from create or update shifts

This commit is contained in:
Matthieu Haineault 2025-11-06 14:45:16 -05:00
parent 7817c3b758
commit efc06b8857
2 changed files with 4 additions and 19 deletions

View File

@ -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<CreateShiftResult[]> {
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<UpdateShiftResult[]> {
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 };
});
}

View File

@ -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 };