// resources/js/services/TimesheetService.ts import axios, { AxiosResponse } from 'axios'; import { Timesheet, TimesheetEntry } from '@/types'; import { update } from '@/routes/password'; const API_URL = '/api/timesheets'; const ENTRY_API_URL = '/api/timesheet-entries'; export default { /** * Retrieves all timesheets * @returns Promise */ async getAllTimesheets(): Promise { const response = await axios.get(API_URL); return response.data; }, /** * Creates a new timesheet * @param timesheet - The timesheet data to create * @returns Promise */ async createTimesheet(timesheet: Partial): Promise { const response = await axios.post(API_URL, timesheet); return response.data; }, /** * Update an existing timesheet * @param timesheet - The Timesheet object to update * @returns */ async updateTimesheet(timesheet: Partial): Promise { const response = await axios.put(`${API_URL}/${timesheet.id}`, timesheet); return response.data; }, /** * Deletes a timesheet by ID * @param timesheetId - The id of the timesheet to delete * @returns Promise */ async deleteTimesheet(timesheetId: number): Promise { const response = await axios.delete(`${API_URL}/${timesheetId}`); return response.data; }, /** * Retrieves all entries for a specific timesheet * @param timesheetId - The ID of the timesheet * @returns Promise */ async getTimesheetEntries(timesheetId: number): Promise { const response = await axios.get(`${API_URL}/${timesheetId}/entries`); return response.data; }, /** * Retrieves all timesheet entries * @returns Promise */ async getAllEntries(): Promise { const response = await axios.get(ENTRY_API_URL); return response.data; }, /** * Creates a new timesheet entry * @param entry - The entry data to create * @returns Promise */ async createEntry(entry: Partial): Promise { const response = await axios.post(ENTRY_API_URL, entry); return response.data; }, /** * Updates an existing timesheet entry * @param entry - The TimesheetEntry object to update * @returns Promise */ async updateEntry(entry: Partial): Promise { const response = await axios.put(`${ENTRY_API_URL}/${entry.id}`, entry); return response.data; }, /** * Toggles the billed status of a timesheet entry * @param entryId - The ID of the entry to toggle * @returns Promise */ async toggleBilled(entryId: number): Promise { const response = await axios.patch(`${ENTRY_API_URL}/${entryId}/toggle-billed`); return response.data; }, /** * Deletes a timesheet entry * @param entryId - The ID of the entry to delete * @returns Promise */ async deleteEntry(entryId: number): Promise { await axios.delete(`${ENTRY_API_URL}/${entryId}`); } };