fix(presets): fix minor issue with adding a daily preset
This commit is contained in:
parent
4f0f5ae30f
commit
e67ed22bad
|
|
@ -300,6 +300,20 @@
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"/schedule-presets/apply-day-preset": {
|
||||||
|
"post": {
|
||||||
|
"operationId": "SchedulePresetsController_applyPresetToDay",
|
||||||
|
"parameters": [],
|
||||||
|
"responses": {
|
||||||
|
"201": {
|
||||||
|
"description": ""
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"tags": [
|
||||||
|
"SchedulePresets"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
"/expense/create": {
|
"/expense/create": {
|
||||||
"post": {
|
"post": {
|
||||||
"operationId": "ExpenseController_create",
|
"operationId": "ExpenseController_create",
|
||||||
|
|
|
||||||
|
|
@ -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 { timesheet_select } from "src/time-and-attendance/utils/selects.utils";
|
||||||
import { ShiftDto } from "src/time-and-attendance/shifts/shift.dto";
|
import { ShiftDto } from "src/time-and-attendance/shifts/shift.dto";
|
||||||
import { WEEKDAY_MAP } from "src/time-and-attendance/schedule-presets/schedule-presets.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()
|
@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>> {
|
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);
|
const employee_id = await this.emailResolver.findIdByEmail(email);
|
||||||
if (!employee_id.success) return { success: false, error: 'EMPLOYEE_NOT_FOUND' };
|
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({
|
const preset_shift = await this.prisma.employees.findFirst({
|
||||||
where: { id: employee_id.data, },
|
where: { id: employee_id.data, },
|
||||||
|
|
@ -95,7 +96,7 @@ export class SchedulePresetsApplyService {
|
||||||
id: true,
|
id: true,
|
||||||
is_default: true,
|
is_default: true,
|
||||||
shifts: {
|
shifts: {
|
||||||
where: { week_day: WEEKDAY_MAP[week_day_index] },
|
where: { week_day: $Enums.Weekday[week_day] },
|
||||||
select: {
|
select: {
|
||||||
bank_code_id: true,
|
bank_code_id: true,
|
||||||
start_time: true,
|
start_time: true,
|
||||||
|
|
@ -108,14 +109,18 @@ export class SchedulePresetsApplyService {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!preset_shift) return { success: false, error: 'EMPLOYEE_NOT_FOUND' };
|
if (!preset_shift) return { success: false, error: 'EMPLOYEE_NOT_FOUND' };
|
||||||
if (!preset_shift.schedule_preset) return { success: false, error: 'SCHEDULE_PRESET_NOT_FOUND' };
|
if (!preset_shift.schedule_preset) return { success: false, error: 'SCHEDULE_PRESET_NOT_FOUND' };
|
||||||
|
|
||||||
for (const shift of preset_shift.schedule_preset.shifts) {
|
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);
|
||||||
}
|
}
|
||||||
// await this.shiftService.createShift(employee_id.data, shift);
|
|
||||||
return { success: true, data: true };
|
return { success: true, data: true };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -132,6 +137,7 @@ export class SchedulePresetsApplyService {
|
||||||
is_approved: false,
|
is_approved: false,
|
||||||
is_remote: preset.is_remote!,
|
is_remote: preset.is_remote!,
|
||||||
};
|
};
|
||||||
|
|
||||||
return { success: true, data: shift };
|
return { success: true, data: shift };
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user