feat(shopping): POST /api/shopping-list/recipe
Some checks failed
Build & Publish Docker Image / build-and-push (push) Has been cancelled
Some checks failed
Build & Publish Docker Image / build-and-push (push) Has been cancelled
This commit is contained in:
18
src/routes/api/shopping-list/recipe/+server.ts
Normal file
18
src/routes/api/shopping-list/recipe/+server.ts
Normal file
@@ -0,0 +1,18 @@
|
||||
import type { RequestHandler } from './$types';
|
||||
import { json } from '@sveltejs/kit';
|
||||
import { z } from 'zod';
|
||||
import { getDb } from '$lib/server/db';
|
||||
import { validateBody } from '$lib/server/api-helpers';
|
||||
import { addRecipeToCart } from '$lib/server/shopping/repository';
|
||||
|
||||
const AddSchema = z.object({
|
||||
recipe_id: z.number().int().positive(),
|
||||
servings: z.number().int().min(1).max(50).optional(),
|
||||
profile_id: z.number().int().positive().optional()
|
||||
});
|
||||
|
||||
export const POST: RequestHandler = async ({ request }) => {
|
||||
const data = validateBody(await request.json().catch(() => null), AddSchema);
|
||||
addRecipeToCart(getDb(), data.recipe_id, data.profile_id ?? null, data.servings);
|
||||
return json({ ok: true }, { status: 201 });
|
||||
};
|
||||
Reference in New Issue
Block a user