feat(shopping): PATCH/DELETE /api/shopping-list/recipe/[id]
Some checks failed
Build & Publish Docker Image / build-and-push (push) Has been cancelled

This commit is contained in:
hsiegeln
2026-04-21 23:23:21 +02:00
parent 7baf60f422
commit 2750c298e9

View File

@@ -0,0 +1,23 @@
import type { RequestHandler } from './$types';
import { json } from '@sveltejs/kit';
import { z } from 'zod';
import { getDb } from '$lib/server/db';
import { parsePositiveIntParam, validateBody } from '$lib/server/api-helpers';
import { removeRecipeFromCart, setCartServings } from '$lib/server/shopping/repository';
const PatchSchema = z.object({
servings: z.number().int().min(1).max(50)
});
export const PATCH: RequestHandler = async ({ params, request }) => {
const id = parsePositiveIntParam(params.recipe_id, 'recipe_id');
const data = validateBody(await request.json().catch(() => null), PatchSchema);
setCartServings(getDb(), id, data.servings);
return json({ ok: true });
};
export const DELETE: RequestHandler = async ({ params }) => {
const id = parsePositiveIntParam(params.recipe_id, 'recipe_id');
removeRecipeFromCart(getDb(), id);
return json({ ok: true });
};