Fixed an oversight in the logic in one of the steps to update and create shifts from the timesheet approval page, which led to update or create requests being sent with the users credentials instead of the employees
38 lines
1.3 KiB
TypeScript
38 lines
1.3 KiB
TypeScript
import { useAuthStore } from "src/stores/auth-store";
|
|
import { useShiftStore } from "src/stores/shift-store";
|
|
import { useTimesheetStore } from "src/stores/timesheet-store";
|
|
|
|
export const useShiftApi = () => {
|
|
const timesheet_store = useTimesheetStore();
|
|
const shift_store = useShiftStore();
|
|
const auth_store = useAuthStore();
|
|
|
|
const deleteShiftById = async (shift_id: number, employee_email?: string) => {
|
|
timesheet_store.is_loading = true;
|
|
const success = await shift_store.deleteShiftById(shift_id, employee_email);
|
|
|
|
if (success) {
|
|
await timesheet_store.getTimesheetsByOptionalEmployeeEmail(auth_store.user?.email ?? '');
|
|
}
|
|
|
|
timesheet_store.is_loading = false;
|
|
};
|
|
|
|
const saveShiftChanges = async (employee_email?: string) => {
|
|
timesheet_store.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 timesheet_store.getTimesheetsByOptionalEmployeeEmail(auth_store.user?.email ?? '');
|
|
}
|
|
|
|
timesheet_store.is_loading = false;
|
|
}
|
|
|
|
return {
|
|
deleteShiftById,
|
|
saveShiftChanges,
|
|
};
|
|
} |