targo-frontend/src/modules/timesheets/composables/use-shift-api.ts

37 lines
1.3 KiB
TypeScript

import { useShiftStore } from "src/stores/shift-store";
import { useTimesheetStore } from "src/stores/timesheet-store";
export const useShiftApi = () => {
const timesheetStore = useTimesheetStore();
const shift_store = useShiftStore();
const deleteShiftById = async (shift_id: number, employee_email?: string) => {
timesheetStore.is_loading = true;
const success = await shift_store.deleteShiftById(shift_id, employee_email);
if (success) {
await timesheetStore.getTimesheetsByOptionalEmployeeEmail(employee_email);
}
timesheetStore.is_loading = false;
};
const saveShiftChanges = async (employee_email?: string) => {
timesheetStore.is_loading = true;
const update_success = await shift_store.updateShifts(employee_email);
const create_success = await shift_store.createNewShifts(employee_email);
if (create_success || update_success){
await timesheetStore.getTimesheetsByOptionalEmployeeEmail(employee_email);
await timesheetStore.getPaidTimeOffTotalsWithOptionalEmployeeEmail();
}
timesheetStore.is_loading = false;
}
return {
deleteShiftById,
saveShiftChanges,
};
}