diff --git a/app/composables/useMachines.js b/app/composables/useMachines.js index 5b39196..31cc6ab 100644 --- a/app/composables/useMachines.js +++ b/app/composables/useMachines.js @@ -97,6 +97,34 @@ export function useMachines() { } } + const addMissingCustomFields = async (machineId, { showToast: shouldShowToast = true } = {}) => { + if (!machineId) { + const error = 'Identifiant de machine manquant' + if (shouldShowToast) { + showError(error) + } + return { success: false, error } + } + + try { + const result = await post(`/machines/${machineId}/add-custom-fields`) + if (result.success) { + if (shouldShowToast) { + showSuccess('Champs personnalisés complétés avec succès') + } + } else if (shouldShowToast && result.error) { + showError(result.error) + } + return result + } catch (error) { + console.error('Erreur lors de l’ajout des champs personnalisés manquants:', error) + if (shouldShowToast) { + showError('Erreur lors de la complétion des champs personnalisés') + } + return { success: false, error: error.message } + } + } + const deleteMachine = async (id) => { loading.value = true try { @@ -143,6 +171,7 @@ export function useMachines() { getMachinesBySite, getMachinesByType, getMachines, - isLoading + isLoading, + addMissingCustomFields } -} +} diff --git a/app/pages/machine/[id].vue b/app/pages/machine/[id].vue index c34f8da..eb19ff4 100644 --- a/app/pages/machine/[id].vue +++ b/app/pages/machine/[id].vue @@ -43,6 +43,20 @@ > Modifier les éléments du squelette +