/** * API pour les documents (photos, notices, factures, etc.) */ import { apiClient, getApiBaseUrl, SuccessResponse } from './client' import { Document, DocumentType, DocumentUpdate, DocumentUploadResponse } from './types' export const documentsApi = { /** * Upload un document */ async upload( file: File, itemId: number, docType: DocumentType, description?: string ): Promise { const formData = new FormData() formData.append('file', file) formData.append('item_id', itemId.toString()) formData.append('doc_type', docType) if (description) { formData.append('description', description) } const response = await apiClient.post('/documents/upload', formData, { headers: { 'Content-Type': 'multipart/form-data', }, }) return response.data }, /** * Récupère tous les documents d'un item */ async getByItem(itemId: number, docType?: DocumentType): Promise { const response = await apiClient.get(`/documents/item/${itemId}`, { params: docType ? { doc_type: docType } : undefined, }) return response.data }, /** * Récupère un document par son ID */ async getById(id: number): Promise { const response = await apiClient.get(`/documents/${id}`) return response.data }, /** * Met à jour les métadonnées d'un document */ async update(id: number, data: DocumentUpdate): Promise { const response = await apiClient.patch(`/documents/${id}`, data) return response.data }, /** * Supprime un document */ async delete(id: number): Promise { await apiClient.delete(`/documents/${id}`) }, /** * Retourne l'URL de téléchargement d'un document */ getDownloadUrl(id: number): string { return `${getApiBaseUrl()}/documents/${id}/download` }, /** * Retourne l'URL d'affichage d'une image */ getImageUrl(id: number): string { return `${getApiBaseUrl()}/documents/${id}/download` }, }