feat(shopping): POST/DELETE /api/shopping-list/check
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:
23
src/routes/api/shopping-list/check/+server.ts
Normal file
23
src/routes/api/shopping-list/check/+server.ts
Normal 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 { validateBody } from '$lib/server/api-helpers';
|
||||
import { toggleCheck } from '$lib/server/shopping/repository';
|
||||
|
||||
const CheckSchema = z.object({
|
||||
name_key: z.string().min(1).max(200),
|
||||
unit_key: z.string().max(50) // kann leer sein
|
||||
});
|
||||
|
||||
export const POST: RequestHandler = async ({ request }) => {
|
||||
const data = validateBody(await request.json().catch(() => null), CheckSchema);
|
||||
toggleCheck(getDb(), data.name_key, data.unit_key, true);
|
||||
return json({ ok: true });
|
||||
};
|
||||
|
||||
export const DELETE: RequestHandler = async ({ request }) => {
|
||||
const data = validateBody(await request.json().catch(() => null), CheckSchema);
|
||||
toggleCheck(getDb(), data.name_key, data.unit_key, false);
|
||||
return json({ ok: true });
|
||||
};
|
||||
Reference in New Issue
Block a user