Merge branch 'main' of git.targo.ca:Targo/targo_backend
This commit is contained in:
commit
ecc8e2a9f6
|
|
@ -10,7 +10,7 @@ import { ShiftsCreateService } from "src/time-and-attendance/shifts/services/shi
|
|||
import { timesheet_select } from "src/time-and-attendance/utils/selects.utils";
|
||||
import { ShiftDto } from "src/time-and-attendance/shifts/shift.dto";
|
||||
import { WEEKDAY_MAP } from "src/time-and-attendance/schedule-presets/schedule-presets.dto";
|
||||
import { Prisma, SchedulePresetShifts } from "@prisma/client";
|
||||
import { $Enums, Prisma, SchedulePresetShifts } from "@prisma/client";
|
||||
|
||||
|
||||
@Injectable()
|
||||
|
|
@ -86,6 +86,7 @@ export class SchedulePresetsApplyService {
|
|||
async applyPresetToDay(email: string, timesheet_id: number, week_day_index: number, date: string): Promise<Result<boolean, string>> {
|
||||
const employee_id = await this.emailResolver.findIdByEmail(email);
|
||||
if (!employee_id.success) return { success: false, error: 'EMPLOYEE_NOT_FOUND' };
|
||||
const week_day = Object.keys(WEEKDAY_MAP)[week_day_index];
|
||||
|
||||
const preset_shift = await this.prisma.employees.findFirst({
|
||||
where: { id: employee_id.data, },
|
||||
|
|
@ -95,7 +96,7 @@ export class SchedulePresetsApplyService {
|
|||
id: true,
|
||||
is_default: true,
|
||||
shifts: {
|
||||
where: { week_day: WEEKDAY_MAP[week_day_index] },
|
||||
where: { week_day: $Enums.Weekday[week_day] },
|
||||
select: {
|
||||
bank_code_id: true,
|
||||
start_time: true,
|
||||
|
|
@ -108,12 +109,17 @@ export class SchedulePresetsApplyService {
|
|||
},
|
||||
},
|
||||
});
|
||||
|
||||
if (!preset_shift) return { success: false, error: 'EMPLOYEE_NOT_FOUND' };
|
||||
if (!preset_shift.schedule_preset) return { success: false, error: 'SCHEDULE_PRESET_NOT_FOUND' };
|
||||
|
||||
for (const shift of preset_shift.schedule_preset.shifts) {
|
||||
await this.createShiftFromPreset(shift, toDateFromString(date), timesheet_id);
|
||||
const created_shift = await this.createShiftFromPreset(shift, toDateFromString(date), timesheet_id);
|
||||
|
||||
if (!created_shift.success)
|
||||
return { success: false, error: 'SHIFT_CREATE_FAILED' }
|
||||
|
||||
await this.shiftService.createShift(employee_id.data, created_shift.data);
|
||||
}
|
||||
return { success: true, data: true };
|
||||
}
|
||||
|
|
@ -131,6 +137,7 @@ export class SchedulePresetsApplyService {
|
|||
is_approved: false,
|
||||
is_remote: preset.is_remote!,
|
||||
};
|
||||
|
||||
return { success: true, data: shift };
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user