innercontext/frontend/src/routes/routines/new/+page.server.ts
Piotr Oleszczyk 9bf94a979c fix: resolve frontend/backend integration bugs
- Rename skincare route prefix /skin-snapshots → /skincare to match API client
- Add redirect_slashes=False to FastAPI app; change collection routes from "/" to ""
  to eliminate 307 redirects on POST/GET without trailing slash
- Fix redirect() inside try/catch in products/new and routines/new server actions
  (SvelteKit redirect() throws and was being caught as a 500 error)
- Eagerly load inventory and steps relationships via explicit SELECT + model_dump(mode="json"),
  working around SQLModel 0.0.37 not serializing Relationship fields in response_model
- Add field_validator for product_effect_profile to coerce DB-returned dict → ProductEffectProfile,
  eliminating Pydantic serializer warning
- Update all tests to use routes without trailing slash

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-02-26 21:53:17 +01:00

28 lines
878 B
TypeScript

import { createRoutine } from '$lib/api';
import { fail, redirect } from '@sveltejs/kit';
import type { Actions, PageServerLoad } from './$types';
export const load: PageServerLoad = async () => {
return { today: new Date().toISOString().slice(0, 10) };
};
export const actions: Actions = {
default: async ({ request }) => {
const form = await request.formData();
const routine_date = form.get('routine_date') as string;
const part_of_day = form.get('part_of_day') as string;
const notes = form.get('notes') as string;
if (!routine_date || !part_of_day) {
return fail(400, { error: 'Date and AM/PM are required' });
}
let routine;
try {
routine = await createRoutine({ routine_date, part_of_day, notes: notes || undefined });
} catch (e) {
return fail(500, { error: (e as Error).message });
}
redirect(303, `/routines/${routine.id}`);
}
};