Add gorgias component and services
This commit is contained in:
39
examples DO NOT USE OR EDIT/EXAMPLE ONLY gorgiasService.js
Normal file
39
examples DO NOT USE OR EDIT/EXAMPLE ONLY gorgiasService.js
Normal file
@@ -0,0 +1,39 @@
|
||||
// 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;
|
||||
Reference in New Issue
Block a user