import { getProfile, updateProfile } from '$lib/api'; import { fail } from '@sveltejs/kit'; import type { Actions, PageServerLoad } from './$types'; export const load: PageServerLoad = async () => { const profile = await getProfile(); return { profile }; }; export const actions: Actions = { save: async ({ request }) => { const form = await request.formData(); const birth_date_raw = String(form.get('birth_date') ?? '').trim(); const sex_at_birth_raw = String(form.get('sex_at_birth') ?? '').trim(); const payload: { birth_date?: string; sex_at_birth?: 'male' | 'female' | 'intersex' } = {}; if (birth_date_raw) payload.birth_date = birth_date_raw; if (sex_at_birth_raw === 'male' || sex_at_birth_raw === 'female' || sex_at_birth_raw === 'intersex') { payload.sex_at_birth = sex_at_birth_raw; } try { const profile = await updateProfile(payload); return { saved: true, profile }; } catch (e) { return fail(502, { error: (e as Error).message }); } } };