mirror of
https://github.com/rjNemo/meal_planner
synced 2026-06-06 02:26:49 +00:00
feat: Add categories endpoint to recipes router
This commit is contained in:
parent
6dffeb5766
commit
2872907a98
1 changed files with 21 additions and 0 deletions
|
|
@ -5,6 +5,13 @@ import { parseRecipeData } from "~/utils/recipes";
|
||||||
|
|
||||||
const { apiUrl } = useRuntimeConfig();
|
const { apiUrl } = useRuntimeConfig();
|
||||||
|
|
||||||
|
type Category = {
|
||||||
|
idCategory: string;
|
||||||
|
strCategory: string;
|
||||||
|
strCategoryThumb: string;
|
||||||
|
strCategoryDescription: string;
|
||||||
|
};
|
||||||
|
|
||||||
export const recipeRouter = router({
|
export const recipeRouter = router({
|
||||||
recipeGet: publicProcedure
|
recipeGet: publicProcedure
|
||||||
.input(
|
.input(
|
||||||
|
|
@ -58,4 +65,18 @@ export const recipeRouter = router({
|
||||||
const recipes = parseRecipeData(data);
|
const recipes = parseRecipeData(data);
|
||||||
return recipes;
|
return recipes;
|
||||||
}),
|
}),
|
||||||
|
categories: publicProcedure.query(async () => {
|
||||||
|
const data = await $fetch<{ categories: Category[] }>(
|
||||||
|
new URL("categories.php", apiUrl).toString(),
|
||||||
|
);
|
||||||
|
|
||||||
|
if (!data?.categories) {
|
||||||
|
throw createError({
|
||||||
|
statusCode: 500,
|
||||||
|
statusMessage: "Failed to fetch categories",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
return data.categories;
|
||||||
|
}),
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue