fix(shifts): ajusted return

This commit is contained in:
Matthieu Haineault 2025-11-06 12:47:36 -05:00
parent 4e48d98c0f
commit e34658fc41
4 changed files with 30 additions and 17 deletions

View File

@ -2,9 +2,9 @@ export class ShiftEntity {
id: number; id: number;
timesheet_id: number; timesheet_id: number;
bank_code_id: number; bank_code_id: number;
date: string; date: Date;
start_time: string; start_time: Date;
end_time: string; end_time: Date;
is_remote: boolean; is_remote: boolean;
is_approved: boolean; is_approved: boolean;
comment?: string; comment?: string;

View File

@ -65,9 +65,18 @@ export class ShiftsUpsertService {
return; return;
} }
const bank_code = await this.typeResolver.findBankCodeIDByType(dto.type); const bank_code = await this.typeResolver.findBankCodeIDByType(dto.type);
const date = await toDateFromString(dto.date);
const start_time = await toHHmmFromString(dto.start_time);
const end_time = await toHHmmFromString(dto.end_time);
const entity: ShiftEntity = { const entity: ShiftEntity = {
timesheet_id: timesheet.id,
bank_code_id: bank_code.id, bank_code_id: bank_code.id,
...dto, date,
start_time,
end_time,
id: dto.id,
is_approved: dto.is_approved,
is_remote: dto.is_remote,
}; };
return { return {
@ -245,10 +254,19 @@ export class ShiftsUpsertService {
const updates: ShiftEntity[] = await Promise.all(dtos.map(async (item) => { const updates: ShiftEntity[] = await Promise.all(dtos.map(async (item) => {
try { try {
const date = await toDateFromString(item.date);
const start_time = await toHHmmFromString(item.start_time);
const end_time = await toHHmmFromString(item.end_time);
const bank_code = await this.typeResolver.findBankCodeIDByType(item.type); const bank_code = await this.typeResolver.findBankCodeIDByType(item.type);
return { return {
id: item.id,
timesheet_id: item.timesheet_id,
bank_code_id: bank_code.id, bank_code_id: bank_code.id,
...item, date,
start_time,
end_time,
is_remote: item.is_remote,
is_approved: item.is_approved,
} }
} catch (error) { } catch (error) {
throw new BadRequestException('INVALID_SHIFT'); throw new BadRequestException('INVALID_SHIFT');
@ -283,9 +301,9 @@ export class ShiftsUpsertService {
const planned_updates = updates.map(update => { const planned_updates = updates.map(update => {
const exist_shift = regroup_id.get(update.id)!; const exist_shift = regroup_id.get(update.id)!;
const normed: Normalized = { const normed: Normalized = {
date: toDateFromString(update.date), date: update.date,
start_time: toHHmmFromString(update.start_time), start_time: update.start_time,
end_time: toHHmmFromString(update.end_time), end_time: update.end_time,
bank_code_id: exist_shift.bank_code_id, bank_code_id: exist_shift.bank_code_id,
}; };
return { update, exist_shift, normed }; return { update, exist_shift, normed };
@ -381,15 +399,11 @@ export class ShiftsUpsertService {
const results: UpdateShiftResult[] = []; const results: UpdateShiftResult[] = [];
for (const planned of planned_updates) { for (const planned of planned_updates) {
try { try {
const date = toStringFromDate(planned.normed.date);
const start_time = toStringFromHHmm(planned.normed.start_time);
const end_time = toStringFromHHmm(planned.normed.end_time);
const data: Partial<ShiftEntity> = { const data: Partial<ShiftEntity> = {
bank_code_id: planned.normed.bank_code_id, bank_code_id: planned.normed.bank_code_id,
date: date, date: planned.normed.date,
start_time: start_time, start_time: planned.normed.start_time,
end_time: end_time, end_time: planned.normed.end_time,
is_remote: planned.update.is_remote, is_remote: planned.update.is_remote,
is_approved: planned.exist_shift.is_approved, is_approved: planned.exist_shift.is_approved,
comment: planned.update.comment, comment: planned.update.comment,

View File

@ -118,7 +118,7 @@ export class GetTimesheetsOverviewService {
type: shift.bank_code?.type ?? '', type: shift.bank_code?.type ?? '',
is_remote: shift.is_remote ?? false, is_remote: shift.is_remote ?? false,
is_approved: shift.is_approved ?? false, is_approved: shift.is_approved ?? false,
shift_id: shift.id ?? null, id: shift.id ?? null,
comment: shift.comment ?? null, comment: shift.comment ?? null,
})); }));

View File

@ -2,7 +2,6 @@ import { Prisma, PrismaClient } from "@prisma/client";
import { GetExpenseDto } from "src/time-and-attendance/expenses/dtos/expense-get.dto"; import { GetExpenseDto } from "src/time-and-attendance/expenses/dtos/expense-get.dto";
import { updateExpenseDto } from "src/time-and-attendance/expenses/dtos/expense-update.dto"; import { updateExpenseDto } from "src/time-and-attendance/expenses/dtos/expense-update.dto";
import { SchedulePresetsDto } from "src/time-and-attendance/time-tracker/schedule-presets/dtos/create-schedule-presets.dto"; import { SchedulePresetsDto } from "src/time-and-attendance/time-tracker/schedule-presets/dtos/create-schedule-presets.dto";
import { ShiftDto } from "src/time-and-attendance/time-tracker/shifts/dtos/shift-create.dto";
import { GetShiftDto } from "src/time-and-attendance/time-tracker/shifts/dtos/shift-get.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 { 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 { UpdateShiftDto } from "src/time-and-attendance/time-tracker/shifts/dtos/shift-update.dto";