From eb166dbc465a00a492c7669b0c5db29b0a1bec07 Mon Sep 17 00:00:00 2001 From: Matthieu Haineault Date: Thu, 6 Nov 2025 16:45:00 -0500 Subject: [PATCH] clean(shifts): clean module of unused features --- .../shifts/controllers/shift.controller.ts | 1 - .../shifts/dtos/shift-update.dto.ts | 11 ------- .../shifts/services/shifts-upsert.service.ts | 30 +++++++++---------- .../time-tracker/shifts/shifts.module.ts | 5 +--- .../utils/selects.utils.ts | 1 - src/time-and-attendance/utils/type.utils.ts | 19 ++---------- 6 files changed, 18 insertions(+), 49 deletions(-) delete mode 100644 src/time-and-attendance/time-tracker/shifts/dtos/shift-update.dto.ts diff --git a/src/time-and-attendance/time-tracker/shifts/controllers/shift.controller.ts b/src/time-and-attendance/time-tracker/shifts/controllers/shift.controller.ts index 70c3034..06b159d 100644 --- a/src/time-and-attendance/time-tracker/shifts/controllers/shift.controller.ts +++ b/src/time-and-attendance/time-tracker/shifts/controllers/shift.controller.ts @@ -1,6 +1,5 @@ import { BadRequestException, Body, Controller, Delete, Param, Patch, Post, Req } from "@nestjs/common"; import { ShiftDto } from "src/time-and-attendance/time-tracker/shifts/dtos/shift-create.dto"; -import { UpdateShiftDto } from "src/time-and-attendance/time-tracker/shifts/dtos/shift-update.dto"; import { ShiftsUpsertService } from "src/time-and-attendance/time-tracker/shifts/services/shifts-upsert.service"; import { CreateShiftResult, UpdateShiftResult } from "src/time-and-attendance/utils/type.utils"; import { RolesAllowed } from "src/common/decorators/roles.decorators"; diff --git a/src/time-and-attendance/time-tracker/shifts/dtos/shift-update.dto.ts b/src/time-and-attendance/time-tracker/shifts/dtos/shift-update.dto.ts deleted file mode 100644 index aef90e3..0000000 --- a/src/time-and-attendance/time-tracker/shifts/dtos/shift-update.dto.ts +++ /dev/null @@ -1,11 +0,0 @@ -import { PartialType, OmitType } from "@nestjs/swagger"; -import { IsInt } from "class-validator"; -import { ShiftDto } from "src/time-and-attendance/time-tracker/shifts/dtos/shift-create.dto"; - -export class UpdateShiftDto extends PartialType( - // allows update using ShiftDto and preventing OmitType variables to be modified - OmitType(ShiftDto, ['is_approved', 'timesheet_id'] as const), -) { - @IsInt() - shift_id!: number; -} 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 0968ea0..510c5c3 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 @@ -8,7 +8,6 @@ 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"; import { ShiftDto } from "src/time-and-attendance/time-tracker/shifts/dtos/shift-create.dto"; -import { response } from "express"; @Injectable() export class ShiftsUpsertService { @@ -226,7 +225,7 @@ export class ShiftsUpsertService { is_approved: false, comment: row.comment ?? undefined, }; - results[index] = { ok: true, data: { shift } }; + results[index] = { ok: true, data: shift }; } return results; @@ -341,19 +340,18 @@ export class ShiftsUpsertService { { start: planned.normed.start_time, end: planned.normed.end_time, date: planned.normed.date }) ); if (conflict) { - return updates.map(exist => - exist.id === planned.exist_shift.id - ? ({ - ok: false, id: exist.id, error: { - error_code: 'SHIFT_OVERLAP', - conflicts: { - start_time: toStringFromHHmm(conflict.start), - end_time: toStringFromHHmm(conflict.end), - date: toStringFromDate(conflict.date), - }, - } - } as UpdateShiftResult) - : ({ ok: false, id: exist.id, error: new BadRequestException('Batch aborted due to overlap in another update') }) + return updates.map(exist => exist.id === planned.exist_shift.id + ? ({ + ok: false, id: exist.id, error: { + error_code: 'SHIFT_OVERLAP', + conflicts: { + start_time: toStringFromHHmm(conflict.start), + end_time: toStringFromHHmm(conflict.end), + date: toStringFromDate(conflict.date), + }, + } + } as UpdateShiftResult) + : ({ ok: false, id: exist.id, error: new BadRequestException('Batch aborted due to overlap in another update') }) ); } } @@ -424,7 +422,7 @@ export class ShiftsUpsertService { comment: row.comment ?? undefined, }; - results.push({ ok: true, id: planned.exist_shift.id, data: { shift: dto } }); + results.push({ ok: true, id: planned.exist_shift.id, data: dto }); } catch (error) { throw new BadRequestException('INVALID_SHIFT'); } diff --git a/src/time-and-attendance/time-tracker/shifts/shifts.module.ts b/src/time-and-attendance/time-tracker/shifts/shifts.module.ts index 3dc407d..6d3773e 100644 --- a/src/time-and-attendance/time-tracker/shifts/shifts.module.ts +++ b/src/time-and-attendance/time-tracker/shifts/shifts.module.ts @@ -1,14 +1,11 @@ -import { BusinessLogicsModule } from 'src/time-and-attendance/domains/business-logics.module'; import { Module } from '@nestjs/common'; import { ShiftController } from 'src/time-and-attendance/time-tracker/shifts/controllers/shift.controller'; -import { ShiftsGetService } from 'src/time-and-attendance/time-tracker/shifts/services/shifts-get.service'; import { ShiftsUpsertService } from 'src/time-and-attendance/time-tracker/shifts/services/shifts-upsert.service'; @Module({ - imports: [ BusinessLogicsModule ], controllers: [ShiftController], - providers: [ ShiftsGetService, ShiftsUpsertService ], + providers: [ ShiftsUpsertService ], exports: [ ShiftsUpsertService ], }) export class ShiftsModule {} diff --git a/src/time-and-attendance/utils/selects.utils.ts b/src/time-and-attendance/utils/selects.utils.ts index fd8476e..98a27ec 100644 --- a/src/time-and-attendance/utils/selects.utils.ts +++ b/src/time-and-attendance/utils/selects.utils.ts @@ -1,5 +1,4 @@ import { Prisma } from "@prisma/client"; -import { dmmfToRuntimeDataModel } from "@prisma/client/runtime/library"; export const expense_select = { id: true, diff --git a/src/time-and-attendance/utils/type.utils.ts b/src/time-and-attendance/utils/type.utils.ts index 4f8ccdc..2d2ef35 100644 --- a/src/time-and-attendance/utils/type.utils.ts +++ b/src/time-and-attendance/utils/type.utils.ts @@ -4,7 +4,6 @@ import { updateExpenseDto } from "src/time-and-attendance/expenses/dtos/expense- import { SchedulePresetsDto } from "src/time-and-attendance/time-tracker/schedule-presets/dtos/create-schedule-presets.dto"; 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"; -import { UpdateShiftDto } from "src/time-and-attendance/time-tracker/shifts/dtos/shift-update.dto"; import { leaveRequestsSelect } from "src/time-and-attendance/utils/selects.utils"; @@ -26,24 +25,15 @@ export type TotalExpenses = { }; export type Normalized = { date: Date; start_time: Date; end_time: Date; bank_code_id: number}; - -export type ShiftWithOvertimeDto = { - shift: GetShiftDto; - // overtime: WeekOvertimeSummary; -}; - -export type CreateShiftResult = { ok: true; data: ShiftWithOvertimeDto } | { ok: false; error: any }; -export type UpdateShiftChanges = Omit; -export type UpdateShiftPayload = { shift_id: number; dto: UpdateShiftChanges }; -export type UpdateShiftResult = { ok: true; id: number; data: ShiftWithOvertimeDto } | { ok: false; id: number; error: any }; -export type DeleteShiftResult = { ok: true; id: number; overtime: WeekOvertimeSummary } | { ok: false; id: number; error: any }; +export type CreateShiftResult = { ok: true; data: GetShiftDto } | { ok: false; error: any }; +export type UpdateShiftResult = { ok: true; id: number; data: GetShiftDto } | { ok: false; id: number; error: any }; export type DeletePresetResult = { ok: true; id: number; } | { ok: false; id: number; error: any }; export type CreatePresetResult = { ok: true; } | { ok: false; error: any }; export type UpdatePresetResult = { ok: true; id: number; data: SchedulePresetsDto } | { ok: false; id: number; error: any }; -export type NormalizedExpense = { date: Date; comment: string; supervisor_comment?: string; }; +export type NormalizedExpense = { date: Date; comment: string; supervisor_comment?: string; }; export type CreateExpenseResult = { ok: true; data: GetExpenseDto } | { ok: false; error: any }; export type UpdateExpensePayload = { id: number; dto: updateExpenseDto }; export type UpdateExpenseResult = { ok: true; id: number; data: GetExpenseDto } | { ok: false; id: number; error: any }; @@ -52,7 +42,6 @@ export type DeleteExpenseResult = { ok: true; id: number; } | { ok: false; id: n export type NormedOk = { index: number; dto: ShiftEntity; normed: Normalized, timesheet_id: number }; -export type NormedErr = { index: number; error: any }; export type ShiftResponse = { @@ -79,8 +68,6 @@ export type ApplyResult = { export type LeaveRequestRow = Prisma.LeaveRequestsGetPayload<{ select: typeof leaveRequestsSelect}>; -export type UpsertAction = 'create' | 'update' | 'delete'; - export type Tx = Prisma.TransactionClient | PrismaClient; export type WeekOvertimeSummary = {