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;
timesheet_id: number;
bank_code_id: number;
date: string;
start_time: string;
end_time: string;
date: Date;
start_time: Date;
end_time: Date;
is_remote: boolean;
is_approved: boolean;
comment?: string;

View File

@ -65,9 +65,18 @@ export class ShiftsUpsertService {
return;
}
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 = {
timesheet_id: timesheet.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 {
@ -245,10 +254,19 @@ export class ShiftsUpsertService {
const updates: ShiftEntity[] = await Promise.all(dtos.map(async (item) => {
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);
return {
id: item.id,
timesheet_id: item.timesheet_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) {
throw new BadRequestException('INVALID_SHIFT');
@ -283,9 +301,9 @@ export class ShiftsUpsertService {
const planned_updates = updates.map(update => {
const exist_shift = regroup_id.get(update.id)!;
const normed: Normalized = {
date: toDateFromString(update.date),
start_time: toHHmmFromString(update.start_time),
end_time: toHHmmFromString(update.end_time),
date: update.date,
start_time: update.start_time,
end_time: update.end_time,
bank_code_id: exist_shift.bank_code_id,
};
return { update, exist_shift, normed };
@ -381,15 +399,11 @@ export class ShiftsUpsertService {
const results: UpdateShiftResult[] = [];
for (const planned of planned_updates) {
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> = {
bank_code_id: planned.normed.bank_code_id,
date: date,
start_time: start_time,
end_time: end_time,
date: planned.normed.date,
start_time: planned.normed.start_time,
end_time: planned.normed.end_time,
is_remote: planned.update.is_remote,
is_approved: planned.exist_shift.is_approved,
comment: planned.update.comment,

View File

@ -118,7 +118,7 @@ export class GetTimesheetsOverviewService {
type: shift.bank_code?.type ?? '',
is_remote: shift.is_remote ?? false,
is_approved: shift.is_approved ?? false,
shift_id: shift.id ?? null,
id: shift.id ?? 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 { 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 { 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 { 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";