95 lines
2.7 KiB
JavaScript
95 lines
2.7 KiB
JavaScript
import api from './axios';
|
|
|
|
export const timeApi = {
|
|
// Get all time entries
|
|
getTimeEntries: async () => {
|
|
try {
|
|
const response = await api.get('/time/entries/');
|
|
return response.data;
|
|
} catch (error) {
|
|
throw new Error('Failed to fetch time entries: ' + error.message);
|
|
}
|
|
},
|
|
|
|
// Get all users (admin only)
|
|
getUsers: async () => {
|
|
try {
|
|
const response = await api.get('/users/');
|
|
return response.data;
|
|
} catch (error) {
|
|
throw new Error('Failed to fetch users: ' + error.message);
|
|
}
|
|
},
|
|
|
|
// Create a new time entry
|
|
createTimeEntry: async (entryData) => {
|
|
try {
|
|
const response = await api.post('/time/entries/create/', entryData);
|
|
return response.data;
|
|
} catch (error) {
|
|
throw new Error('Failed to create time entry: ' + error.message);
|
|
}
|
|
},
|
|
|
|
scanTimeEntry: async (code, options = {}) => {
|
|
try {
|
|
const response = await api.post('/time/entries/scan/', { code, ...options });
|
|
return response.data;
|
|
} catch (error) {
|
|
const scanError = new Error(error.response?.data?.error || `Erreur lors du pointage: ${error.message}`);
|
|
scanError.conflict = error.response?.data?.conflict;
|
|
scanError.code = error.response?.status;
|
|
throw scanError;
|
|
}
|
|
},
|
|
|
|
// Get a specific time entry
|
|
getTimeEntry: async (id) => {
|
|
try {
|
|
const response = await api.get(`/time/entries/${id}/`);
|
|
return response.data;
|
|
} catch (error) {
|
|
throw new Error('Failed to fetch time entry: ' + error.message);
|
|
}
|
|
},
|
|
|
|
// Update a time entry
|
|
updateTimeEntry: async (id, entryData) => {
|
|
try {
|
|
const response = await api.put(`/time/entries/${id}/update/`, entryData);
|
|
return response.data;
|
|
} catch (error) {
|
|
throw new Error('Failed to update time entry: ' + error.message);
|
|
}
|
|
},
|
|
|
|
// Delete a time entry
|
|
deleteTimeEntry: async (id) => {
|
|
try {
|
|
const response = await api.delete(`/time/entries/${id}/`);
|
|
return response.data;
|
|
} catch (error) {
|
|
throw new Error(error.response?.data?.detail || `Erreur lors de la suppression: ${error.message}`);
|
|
}
|
|
},
|
|
|
|
// Get weekly summary for current user
|
|
getWeeklySummary: async () => {
|
|
try {
|
|
const response = await api.get('/time/weekly-summary/');
|
|
return response.data;
|
|
} catch (error) {
|
|
throw new Error('Failed to fetch weekly summary: ' + error.message);
|
|
}
|
|
},
|
|
|
|
// Get weekly summary for a specific user (admin only)
|
|
getUserWeeklySummary: async (userId) => {
|
|
try {
|
|
const response = await api.get(`/time/weekly-summary/${userId}/`);
|
|
return response.data;
|
|
} catch (error) {
|
|
throw new Error('Failed to fetch user weekly summary: ' + error.message);
|
|
}
|
|
},
|
|
}; |