// src/services/gorgiasService.js import axios from "axios"; const API_BASE_URL = "/api/gorgias"; // Helper function for consistent error handling const handleError = (error, context) => { console.error(`Error ${context}:`, error.response?.data || error.message); throw error; }; // Export the service object directly const gorgiasService = { async fetchTickets() { try { const response = await axios.get(`${API_BASE_URL}/tickets`); return response.data.data || []; } catch (error) { handleError(error, "fetching tickets"); } }, async fetchStatistics(name, filters = {}) { if (!name) { throw new Error("Statistic name is required"); } try { const response = await axios.post(`${API_BASE_URL}/stats/${name}`, { filters, }); return response.data; } catch (error) { handleError(error, `fetching statistics: ${name}`); } }, }; export default gorgiasService;