Files
kochwas/src/routes/api/recipes/blank/+server.ts

31 lines
904 B
TypeScript
Raw Normal View History

import type { RequestHandler } from './$types';
import { json } from '@sveltejs/kit';
import { getDb } from '$lib/server/db';
import { insertRecipe } from '$lib/server/recipes/repository';
// Legt ein leeres Rezept an und gibt die ID zurück. Der Client leitet
// danach nach /recipes/{id}?edit=1 um, damit der Editor sofort offen ist.
// Titel "Neues Rezept" ist ein Platzhalter — der User überschreibt ihn
// beim ersten Speichern.
export const POST: RequestHandler = async () => {
const id = insertRecipe(getDb(), {
id: null,
title: 'Neues Rezept',
description: null,
source_url: null,
source_domain: null,
image_path: null,
servings_default: 4,
servings_unit: null,
prep_time_min: null,
cook_time_min: null,
total_time_min: null,
cuisine: null,
category: null,
ingredients: [],
steps: [],
tags: []
});
return json({ id });
};