2026-04-17 15:23:00 +02:00
|
|
|
import type { RequestHandler } from './$types';
|
2026-04-18 22:19:12 +02:00
|
|
|
import { json } from '@sveltejs/kit';
|
2026-04-17 15:23:00 +02:00
|
|
|
import { z } from 'zod';
|
|
|
|
|
import { getDb } from '$lib/server/db';
|
2026-04-18 22:19:12 +02:00
|
|
|
import { parsePositiveIntParam, validateBody } from '$lib/server/api-helpers';
|
2026-04-17 15:23:00 +02:00
|
|
|
import { logCooked } from '$lib/server/recipes/actions';
|
2026-04-17 22:23:08 +02:00
|
|
|
import { removeFromWishlistForAll } from '$lib/server/wishlist/repository';
|
2026-04-17 15:23:00 +02:00
|
|
|
|
|
|
|
|
const Schema = z.object({ profile_id: z.number().int().positive() });
|
|
|
|
|
|
|
|
|
|
export const POST: RequestHandler = async ({ params, request }) => {
|
2026-04-18 22:19:12 +02:00
|
|
|
const id = parsePositiveIntParam(params.id, 'id');
|
|
|
|
|
const data = validateBody(await request.json().catch(() => null), Schema);
|
2026-04-17 22:23:08 +02:00
|
|
|
const db = getDb();
|
2026-04-18 22:19:12 +02:00
|
|
|
const entry = logCooked(db, id, data.profile_id);
|
2026-04-17 22:23:08 +02:00
|
|
|
// Wenn das Rezept heute gekocht wurde, ist der Wunsch erfüllt — für alle
|
|
|
|
|
// Profile raus aus der Wunschliste. Client nutzt den removed_from_wishlist-
|
|
|
|
|
// Flag, um den lokalen State (Badge, Button) ohne Reload zu aktualisieren.
|
|
|
|
|
removeFromWishlistForAll(db, id);
|
|
|
|
|
return json({ ...entry, removed_from_wishlist: true }, { status: 201 });
|
2026-04-17 15:23:00 +02:00
|
|
|
};
|