From 7a4a77e3fc5666bc2e965bf87db8134e64cb3c63 Mon Sep 17 00:00:00 2001 From: Matthieu Date: Mon, 23 Mar 2026 15:31:52 +0100 Subject: [PATCH] feat(documents) : add document type constants and updateDocument method Co-Authored-By: Claude Opus 4.6 (1M context) --- app/composables/useDocuments.ts | 33 ++++++++++++++++++++++++++++++++- app/shared/documentTypes.ts | 15 +++++++++++++++ 2 files changed, 47 insertions(+), 1 deletion(-) create mode 100644 app/shared/documentTypes.ts diff --git a/app/composables/useDocuments.ts b/app/composables/useDocuments.ts index e9c9324..842a68a 100644 --- a/app/composables/useDocuments.ts +++ b/app/composables/useDocuments.ts @@ -11,6 +11,7 @@ export interface Document { size: number fileUrl: string downloadUrl: string + type?: string /** @deprecated Legacy Base64 data URI — use fileUrl instead */ path?: string createdAt?: string @@ -32,6 +33,7 @@ export interface UploadContext { composantId?: string productId?: string pieceId?: string + type?: string } export interface DocumentResult { @@ -63,7 +65,7 @@ const extractTotal = (payload: unknown, fallbackLength: number): number => { } export function useDocuments() { - const { get, postFormData, delete: del } = useApi() + const { get, patch, postFormData, delete: del } = useApi() const { showError, showSuccess } = useToast() const loadFromEndpoint = async ( @@ -218,6 +220,7 @@ export function useDocuments() { const formData = new FormData() formData.append('file', file) formData.append('name', file.name) + if (context.type) formData.append('type', context.type) if (context.siteId) formData.append('siteId', context.siteId) if (context.machineId) formData.append('machineId', context.machineId) @@ -280,6 +283,33 @@ export function useDocuments() { } } + const updateDocument = async ( + id: string, + data: { name?: string; type?: string }, + ): Promise => { + loading.value = true + try { + const result = await patch(`/documents/${id}`, data) + if (result.success && result.data) { + const updated = result.data as Document + const index = documents.value.findIndex((doc) => doc.id === id) + if (index !== -1) { + documents.value[index] = { ...documents.value[index], ...updated } + } + showSuccess('Document mis à jour') + return { success: true, data: updated } + } + if (result.error) showError(result.error) + return result as DocumentResult + } catch (error) { + const err = error as Error + showError('Impossible de mettre à jour le document') + return { success: false, error: err.message } + } finally { + loading.value = false + } + } + return { documents, total, @@ -292,6 +322,7 @@ export function useDocuments() { loadDocumentsByPiece, loadDocumentsByProduct, uploadDocuments, + updateDocument, deleteDocument, } } diff --git a/app/shared/documentTypes.ts b/app/shared/documentTypes.ts new file mode 100644 index 0000000..2b60f00 --- /dev/null +++ b/app/shared/documentTypes.ts @@ -0,0 +1,15 @@ +export const DOCUMENT_TYPES = [ + { value: 'documentation', label: 'Documentation' }, + { value: 'devis', label: 'Devis' }, + { value: 'facture', label: 'Facture' }, + { value: 'plan', label: 'Plan' }, + { value: 'photo', label: 'Photo' }, + { value: 'autre', label: 'Autre' }, +] as const + +export type DocumentTypeValue = (typeof DOCUMENT_TYPES)[number]['value'] + +export const getDocumentTypeLabel = (value: string): string => { + const found = DOCUMENT_TYPES.find((t) => t.value === value) + return found?.label ?? value +}