Lin / frontend /src /services /scheduleService.js
Zelyanoth's picture
fff
25f22bf
raw
history blame
2.44 kB
import apiClient from './apiClient';
class ScheduleService {
/**
* Get all schedules for the current user
* @returns {Promise} Promise that resolves to the schedules data
*/
async getAll() {
try {
const response = await apiClient.get('/schedules');
if (import.meta.env.VITE_NODE_ENV === 'development') {
console.log('πŸ“… [Schedule] Retrieved schedules:', response.data);
}
return response;
} catch (error) {
if (import.meta.env.VITE_NODE_ENV === 'development') {
console.error('πŸ“… [Schedule] Get schedules error:', error.response?.data || error.message);
}
throw error;
}
}
/**
* Create a new schedule
* @param {Object} scheduleData - Schedule data
* @param {string} scheduleData.social_network - Social account ID
* @param {string} scheduleData.schedule_time - Schedule time in format "HH:MM"
* @param {Array<string>} scheduleData.days - List of days to schedule
* @returns {Promise} Promise that resolves to the create schedule response
*/
async create(scheduleData) {
try {
const response = await apiClient.post('/schedules', {
social_network: scheduleData.social_network,
schedule_time: scheduleData.schedule_time,
days: scheduleData.days
});
if (import.meta.env.VITE_NODE_ENV === 'development') {
console.log('πŸ“… [Schedule] Schedule created:', response.data);
}
return response;
} catch (error) {
if (import.meta.env.VITE_NODE_ENV === 'development') {
console.error('πŸ“… [Schedule] Create schedule error:', error.response?.data || error.message);
}
throw error;
}
}
/**
* Delete a schedule
* @param {string} scheduleId - Schedule ID
* @returns {Promise} Promise that resolves to the delete schedule response
*/
async delete(scheduleId) {
try {
const response = await apiClient.delete(`/schedules/${scheduleId}`);
if (import.meta.env.VITE_NODE_ENV === 'development') {
console.log('πŸ“… [Schedule] Schedule deleted:', response.data);
}
return response;
} catch (error) {
if (import.meta.env.VITE_NODE_ENV === 'development') {
console.error('πŸ“… [Schedule] Delete schedule error:', error.response?.data || error.message);
}
throw error;
}
}
}
export default new ScheduleService();