|
| 1 | +import { apiRequest } from './client'; |
| 2 | +import type { |
| 3 | + Organization, |
| 4 | + CreateOrganization, |
| 5 | + UpdateOrganization, |
| 6 | + OrganizationUser, |
| 7 | + ManageOrganizationUser, |
| 8 | +} from '../types/Organization.ts'; |
| 9 | +import type { Event } from '../types/Event.ts'; |
| 10 | +import type { QueryParams } from '../types/QueryParams.ts'; |
| 11 | + |
| 12 | +export const organizationsApi = { |
| 13 | + // Get all organizations |
| 14 | + getAll: (params?: QueryParams) => { |
| 15 | + const query = new URLSearchParams(); |
| 16 | + if (params?.limit !== undefined) { |
| 17 | + query.append('limit', params.limit.toString()); |
| 18 | + } |
| 19 | + if (params?.offset !== undefined) { |
| 20 | + query.append('offset', params.offset.toString()); |
| 21 | + } |
| 22 | + const queryString = query.toString(); |
| 23 | + return apiRequest<Organization[]>(queryString ? `/organizations?${queryString}` : '/organizations'); |
| 24 | + }, |
| 25 | + |
| 26 | + // Create organization |
| 27 | + create: (data: CreateOrganization) => |
| 28 | + apiRequest<Organization, CreateOrganization>(`/events`, { |
| 29 | + method: 'POST', |
| 30 | + body: data, |
| 31 | + }), |
| 32 | + |
| 33 | + // Get organization |
| 34 | + getById: (oid: string) => apiRequest<Organization>(`/organizations/${oid}`), |
| 35 | + |
| 36 | + // Update organization |
| 37 | + update: (oid: string, data: UpdateOrganization) => |
| 38 | + apiRequest<Organization, UpdateOrganization>(`/organizations/${oid}`, { |
| 39 | + method: 'PUT', |
| 40 | + body: data, |
| 41 | + }), |
| 42 | + |
| 43 | + // Delete organization |
| 44 | + delete: (oid: string) => |
| 45 | + apiRequest<void>(`/organizations/${oid}`, { |
| 46 | + method: 'DELETE', |
| 47 | + }), |
| 48 | + |
| 49 | + // Get organization's events |
| 50 | + events: (oid: string, params?: QueryParams) => { |
| 51 | + const query = new URLSearchParams(); |
| 52 | + if (params?.limit !== undefined) { |
| 53 | + query.append('limit', params.limit.toString()); |
| 54 | + } |
| 55 | + if (params?.offset !== undefined) { |
| 56 | + query.append('offset', params.offset.toString()); |
| 57 | + } |
| 58 | + const queryString = query.toString(); |
| 59 | + return apiRequest<Event[]>( |
| 60 | + queryString ? `/organizations/${oid}/events?${queryString}` : `/organizations/${oid}/events` |
| 61 | + ); |
| 62 | + }, |
| 63 | + // Get organization's members |
| 64 | + getMembers: (oid: string) => apiRequest<OrganizationUser>(`/organizations/${oid}/members`), |
| 65 | + |
| 66 | + // Add member to organization |
| 67 | + addMember: (oid: string, data: ManageOrganizationUser) => |
| 68 | + apiRequest<void, ManageOrganizationUser>(`/organizations/${oid}/members`, { |
| 69 | + method: 'POST', |
| 70 | + body: data, |
| 71 | + }), |
| 72 | + |
| 73 | + // Remove organization member |
| 74 | + deleteMember: (oid: string, data: ManageOrganizationUser) => |
| 75 | + apiRequest<void, ManageOrganizationUser>(`/organizations/${oid}/members`, { |
| 76 | + method: 'DELETE', |
| 77 | + body: data, |
| 78 | + }), |
| 79 | +}; |
0 commit comments