41 lines
1.6 KiB
TypeScript
41 lines
1.6 KiB
TypeScript
import { api } from './client';
|
|
import type {
|
|
ContentCollectionRecord,
|
|
CreateContentCollectionPayload,
|
|
UpdateContentCollectionPayload,
|
|
} from './types';
|
|
|
|
export const contentCollectionsApi = {
|
|
async list(params?: { organization?: string }): Promise<ContentCollectionRecord[]> {
|
|
const sp = new URLSearchParams();
|
|
sp.set('limit', '200');
|
|
if (params?.organization) sp.set('organization', params.organization);
|
|
const r = await api.get<{ collections: ContentCollectionRecord[] }>(`/content-collections?${sp}`);
|
|
if (r.error) throw new Error(r.error);
|
|
return r.data?.collections ?? [];
|
|
},
|
|
|
|
async create(payload: CreateContentCollectionPayload): Promise<ContentCollectionRecord> {
|
|
const r = await api.post<ContentCollectionRecord>('/content-collections', payload);
|
|
if (r.error || !r.data) throw new Error(r.error ?? 'Failed to create collection');
|
|
return r.data;
|
|
},
|
|
|
|
async get(id: string): Promise<ContentCollectionRecord> {
|
|
const r = await api.get<ContentCollectionRecord>(`/content-collections/${id}`);
|
|
if (r.error || !r.data) throw new Error(r.error ?? 'Not found');
|
|
return r.data;
|
|
},
|
|
|
|
async update(id: string, payload: UpdateContentCollectionPayload): Promise<ContentCollectionRecord> {
|
|
const r = await api.put<ContentCollectionRecord>(`/content-collections/${id}`, payload);
|
|
if (r.error || !r.data) throw new Error(r.error ?? 'Failed to update collection');
|
|
return r.data;
|
|
},
|
|
|
|
async remove(id: string): Promise<void> {
|
|
const r = await api.delete<unknown>(`/content-collections/${id}`);
|
|
if (r.error) throw new Error(r.error);
|
|
},
|
|
};
|