import { useAuthStore } from "src/stores/auth-store"; import { useTimesheetStore } from "src/stores/timesheet-store" export const useTimesheetApi = () => { const timesheet_store = useTimesheetStore(); const auth_store = useAuthStore(); const getTimesheetsByDate = async (date_string: string, employee_email?: string) => { timesheet_store.is_loading = true; const success = await timesheet_store.getPayPeriodByDateOrYearAndNumber(date_string); if (success) { await timesheet_store.getTimesheetsByEmployeeEmail(employee_email ?? auth_store.user?.email ?? ''); timesheet_store.is_loading = false; } timesheet_store.is_loading = false; } const getTimesheetsByCurrentPayPeriod = async (employee_email?: string) => { if (timesheet_store.pay_period === undefined) return false; timesheet_store.is_loading = true; const success = await timesheet_store.getPayPeriodByDateOrYearAndNumber(timesheet_store.pay_period.pay_year, timesheet_store.pay_period.pay_period_no ); if (success) { await timesheet_store.getTimesheetsByEmployeeEmail(employee_email ?? auth_store.user?.email ?? ''); timesheet_store.is_loading = false; } timesheet_store.is_loading = false; }; return { getTimesheetsByDate, getTimesheetsByCurrentPayPeriod, }; };