42 lines
1014 B
TypeScript
42 lines
1014 B
TypeScript
import { error } from '@sveltejs/kit';
|
|
import type { PageServerLoad } from './$types';
|
|
import { apiClient } from '$lib/server/api';
|
|
|
|
export const load: PageServerLoad = async ({ fetch, params }) => {
|
|
const api = apiClient(fetch);
|
|
const { data, error: apiError } = await api.GET('/v1/recipes/{id}', {
|
|
params: { path: { id: params.id } }
|
|
});
|
|
|
|
if (apiError || !data) {
|
|
error(404, 'Recipe not found');
|
|
}
|
|
|
|
return {
|
|
recipe: {
|
|
id: data.id!,
|
|
name: data.name!,
|
|
serves: data.serves,
|
|
cookTimeMin: data.cookTimeMin,
|
|
effort: data.effort,
|
|
heroImageUrl: data.heroImageUrl,
|
|
ingredients: (data.ingredients ?? []).map((ing) => ({
|
|
ingredientId: ing.ingredientId,
|
|
name: ing.name,
|
|
quantity: ing.quantity,
|
|
unit: ing.unit,
|
|
sortOrder: ing.sortOrder
|
|
})),
|
|
steps: (data.steps ?? []).map((s) => ({
|
|
stepNumber: s.stepNumber,
|
|
instruction: s.instruction
|
|
})),
|
|
tags: (data.tags ?? []).map((t) => ({
|
|
id: t.id!,
|
|
name: t.name!,
|
|
tagType: t.tagType
|
|
}))
|
|
}
|
|
};
|
|
};
|