diff --git a/frontend/src/lib/types.ts b/frontend/src/lib/types.ts index b644a49..16aed33 100644 --- a/frontend/src/lib/types.ts +++ b/frontend/src/lib/types.ts @@ -181,7 +181,7 @@ export interface Routine { notes?: string; created_at: string; updated_at: string; - steps: RoutineStep[]; + steps?: RoutineStep[]; } export interface GroomingSchedule { diff --git a/frontend/src/routes/routines/+page.svelte b/frontend/src/routes/routines/+page.svelte index 28fa6fe..bea4647 100644 --- a/frontend/src/routes/routines/+page.svelte +++ b/frontend/src/routes/routines/+page.svelte @@ -47,7 +47,7 @@ {routine.part_of_day.toUpperCase()} - {routine.steps.length} steps + {routine.steps?.length ?? 0} steps {#if routine.notes} {routine.notes} diff --git a/frontend/src/routes/routines/suggest/+page.server.ts b/frontend/src/routes/routines/suggest/+page.server.ts index 026a352..f4d022a 100644 --- a/frontend/src/routes/routines/suggest/+page.server.ts +++ b/frontend/src/routes/routines/suggest/+page.server.ts @@ -74,8 +74,10 @@ export const actions: Actions = { return fail(400, { error: 'Nieprawidłowy format kroków.' }); } + let routineId: string; try { const routine = await createRoutine({ routine_date, part_of_day }); + routineId = routine.id; for (let i = 0; i < steps.length; i++) { const s = steps[i]; await addRoutineStep(routine.id, { @@ -87,10 +89,10 @@ export const actions: Actions = { region: s.region || undefined }); } - redirect(303, `/routines/${routine.id}`); } catch (e) { return fail(500, { error: (e as Error).message }); } + redirect(303, `/routines/${routineId}`); }, saveBatch: async ({ request }) => {