From 8ad8076f4dbbe579ffc7b9ccad29467bf18db85f Mon Sep 17 00:00:00 2001 From: Matthieu Haineault Date: Tue, 14 Oct 2025 10:58:43 -0400 Subject: [PATCH] fix(shifts): fix bank_code_id by type --- src/modules/shifts/helpers/shifts.helpers.ts | 1 + src/modules/shifts/services/shifts-command.service.ts | 10 ++++++---- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/modules/shifts/helpers/shifts.helpers.ts b/src/modules/shifts/helpers/shifts.helpers.ts index bfab937..62da22d 100644 --- a/src/modules/shifts/helpers/shifts.helpers.ts +++ b/src/modules/shifts/helpers/shifts.helpers.ts @@ -94,6 +94,7 @@ export class ShiftsHelpersService { date_only: Date; norm: Normalized; bank_code_id: number; + comment?: string; }, ) { const { timesheet_id, date_only, norm, bank_code_id } = params; diff --git a/src/modules/shifts/services/shifts-command.service.ts b/src/modules/shifts/services/shifts-command.service.ts index 8870a64..1592233 100644 --- a/src/modules/shifts/services/shifts-command.service.ts +++ b/src/modules/shifts/services/shifts-command.service.ts @@ -8,6 +8,7 @@ import { PrismaService } from "src/prisma/prisma.service"; import { toDateOnly } from "../helpers/shifts-date-time-helpers"; import { UpsertAction } from "src/modules/shared/types/upsert-actions.types"; import { ShiftsHelpersService } from "../helpers/shifts.helpers"; +import { BankCodesResolver } from "src/modules/shared/utils/resolve-bank-type-id.utils"; @Injectable() export class ShiftsCommandService extends BaseApprovalService { @@ -16,6 +17,7 @@ export class ShiftsCommandService extends BaseApprovalService { constructor( prisma: PrismaService, private readonly emailResolver: EmailToIdResolver, + private readonly typeResolver: BankCodesResolver, private readonly helpersService: ShiftsHelpersService, ) { super(prisma); } @@ -99,7 +101,7 @@ export class ShiftsCommandService extends BaseApprovalService { end_time: new_norm_shift.end_time, is_remote: new_norm_shift.is_remote, is_approved: new_norm_shift.is_approved, - comment: new_norm_shift.comment ?? '', + comment: new_norm_shift.comment ?? null, bank_code_id: new_bank_code_id, }, }); @@ -144,7 +146,7 @@ export class ShiftsCommandService extends BaseApprovalService { start_time: new_norm_shift.start_time, end_time: new_norm_shift.end_time, is_remote: new_norm_shift.is_remote, - comment: new_norm_shift.comment ?? '', + comment: new_norm_shift.comment ?? null, bank_code_id: new_bank_code_id, }, }); @@ -169,13 +171,13 @@ export class ShiftsCommandService extends BaseApprovalService { const { id: timesheet_id } = await this.helpersService.ensureTimesheet(tx, employee_id, date_only); const old_norm_shift = await this.helpersService.normalizeRequired(dto.old_shift, 'old_shift'); - const old_bank_code_id = await this.helpersService.resolveBankIdRequired(tx, old_norm_shift.type, 'old_shift'); + const old_bank_code_id = await this.typeResolver.findByType(old_norm_shift.type); const existing = await this.helpersService.findExactOldShift(tx, { timesheet_id, date_only, norm: old_norm_shift, - bank_code_id: old_bank_code_id, + bank_code_id: old_bank_code_id.id, }); if(!existing) throw new NotFoundException('[SHIFT_STALE]- The shift was modified or deleted by someone else');