import api from './axios.js'; export const timeApi = { getTimeEntries: async () => (await api.get('/time/entries/')).data, getAttendances: async () => (await api.get('/time/entries/')).data, getUsers: async () => (await api.get('/users/')).data, createTimeEntry: async (data) => (await api.post('/time/entries/create/', data)).data, getTimeEntry: async (id) => (await api.get(`/time/entries/${id}/`)).data, updateTimeEntry: async (id, data) => (await api.patch(`/time/entries/${id}/`, data)).data, deleteTimeEntry: async (id) => (await api.delete(`/time/entries/${id}/`)).data, updateTimeEntryGroup: async (id, data) => (await api.patch(`/time/groups/${id}/`, data)).data, deleteTimeEntryGroup: async (id) => (await api.delete(`/time/groups/${id}/`)).data, getWeeklySummary: async () => (await api.get('/time/weekly-summary/')).data, getUserWeeklySummary: async (id) => (await api.get(`/time/weekly-summary/${id}/`)).data, scanTimeEntry: async (code, options = {}) => { try { return (await api.post('/time/entries/scan/', { code, ...options })).data; } catch (error) { const data = error.response?.data || {}; error.conflict = data.conflict; error.resolution = data.resolution; error.missingTime = data.missing_time; error.scanTime = data.scan_time; error.scanDate = data.scan_date; error.entryId = data.entry_id; error.code = error.response?.status; throw error; } }, };