import { api } from "@/lib/api"; import { normalizeCollection } from "@/lib/normalizers"; import type { Collection } from "@/types"; export const collectionsApi = { getAll: () => api .get("/collections") .then((r) => r.data.map(normalizeCollection)), getById: (id: number) => api .get(`/collections/${id}`) .then((r) => normalizeCollection(r.data)), create: (data: Partial) => api.post("/collections", data).then((r) => r.data), update: (id: number, data: Partial) => api .put(`/collections/${id}`, data) .then((r) => normalizeCollection(r.data)), updateWithMedia: (id: number, formData: FormData) => api .put(`/collections/${id}`, formData, { headers: { "Content-Type": "multipart/form-data" }, }) .then((r) => normalizeCollection(r.data)), delete: (id: number) => api.delete(`/collections/${id}`).then((r) => r.data), getCollectionParts: (id: number) => api .put(`/collections/${id}/parts`) .then((r) => normalizeCollection(r.data)), addEntry: (collectionId: number, entryId: number) => api .post(`/collections/${collectionId}/entries/${entryId}`, {}) .then((r) => r.data), removeEntry: (collectionId: number, entryId: number) => api .delete(`/collections/${collectionId}/entries/${entryId}`) .then((r) => r.data), };