import api from './api'; const ENDPOINTS = { ORGANIZATIONS: 'organizations', ORGANIZATION_BY_ID: (id) => `organizations/${id}`, }; export const organizationsApi = { // Get all organizations getAllOrganizations: async (params = {}) => { try { const response = await api.get(ENDPOINTS.ORGANIZATIONS, { params }); return response.data; } catch (error) { console.error('Error fetching organizations:', error); throw error; } }, // Get organization by ID getOrganizationById: async (id) => { try { const response = await api.get(ENDPOINTS.ORGANIZATION_BY_ID(id)); return response.data; } catch (error) { console.error(`Error fetching organization ${id}:`, error); throw error; } }, // Create organization createOrganization: async (data) => { try { const response = await api.post(ENDPOINTS.ORGANIZATIONS, data); return response.data; } catch (error) { console.error('Error creating organization:', error); throw error; } }, // Update organization updateOrganization: async (id, data) => { try { const response = await api.put(ENDPOINTS.ORGANIZATION_BY_ID(id), data); return response.data; } catch (error) { console.error(`Error updating organization ${id}:`, error); throw error; } }, // Delete organization deleteOrganization: async (id) => { try { const response = await api.delete(ENDPOINTS.ORGANIZATION_BY_ID(id)); return response.data; } catch (error) { console.error(`Error deleting organization ${id}:`, error); throw error; } }, // Bulk update bulkUpdate: async (organizations) => { try { const response = await api.put(`${ENDPOINTS.ORGANIZATIONS}/bulk`, { organizations, }); return response.data; } catch (error) { console.error('Error bulk updating organizations:', error); throw error; } }, // Bulk delete bulkDelete: async (ids) => { try { const response = await api.delete(`${ENDPOINTS.ORGANIZATIONS}/bulk`, { data: { ids }, }); return response.data; } catch (error) { console.error('Error bulk deleting organizations:', error); throw error; } }, }; export default organizationsApi;