From d8fc93ff5d6eb3c3ac4ff0595940dc1187d95f39 Mon Sep 17 00:00:00 2001 From: neckfire Date: Sun, 19 Jul 2026 03:24:37 +0200 Subject: [PATCH] =?UTF-8?q?fix:=20d=C3=A9ballage=20resource=20{data}=20+?= =?UTF-8?q?=20cl=C3=A9=20useAsyncData=20sur=20d=C3=A9tail=20exercice/s?= =?UTF-8?q?=C3=A9ance?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Claude Opus 4.8 (1M context) --- app/pages/exercises/[id].vue | 36 +++++++++++++++++++----------------- app/pages/session/[id].vue | 6 +++++- 2 files changed, 24 insertions(+), 18 deletions(-) diff --git a/app/pages/exercises/[id].vue b/app/pages/exercises/[id].vue index 00f1c0e..1b7064e 100644 --- a/app/pages/exercises/[id].vue +++ b/app/pages/exercises/[id].vue @@ -6,7 +6,7 @@ const route = useRoute() interface ExerciseDetail { id: number name: string - body_part: string | null + body_part?: string | null category: string | null equipment: string | null target: string | null @@ -18,10 +18,12 @@ interface ExerciseDetail { attribution: string | null } -const { data, pending } = await useAsyncData( - () => `exercise-${route.params.id}`, - () => api(`/api/exercises/${route.params.id}`, { query: { locale: locale.value } }), - { watch: [locale] } +// L'API enveloppe la resource dans { data: {...} } → on déballe. +const { data: ex, pending } = await useAsyncData( + `exercise-${route.params.id}`, + () => api<{ data: ExerciseDetail }>(`/api/exercises/${route.params.id}`, { query: { locale: locale.value } }) + .then(r => r.data), + { watch: [() => route.params.id, locale] } ) @@ -29,38 +31,38 @@ const { data, pending } = await useAsyncData(
-
+
- diff --git a/app/pages/session/[id].vue b/app/pages/session/[id].vue index 9efd599..7e08b27 100644 --- a/app/pages/session/[id].vue +++ b/app/pages/session/[id].vue @@ -10,7 +10,11 @@ interface SetLog { id: number, exercise_id: number, set_number: number, reps: nu interface Exercise { id: number, name: string, image_url: string | null, target?: string | null } interface Session { id: number, title: string | null, status: string, set_logs: (SetLog & { exercise?: Exercise })[] } -const { data: session, refresh } = await useAsyncData(`session-${sessionId}`, () => api(`/api/sessions/${sessionId}`)) +// L'API peut envelopper la resource dans { data: {...} } → déballage tolérant. +const { data: session, refresh } = await useAsyncData( + `session-${sessionId}`, + () => api(`/api/sessions/${sessionId}`).then((r: unknown) => (r as { data?: Session })?.data ?? r as Session) +) // Exercices actifs = ceux ayant des sets + ceux ajoutés manuellement const added = ref([])