refactor(api): parsePositiveIntParam fuer view-endpoint

Code-Review-Finding zu commit 82d4348: das Sibling-Endpoint
recipes/[id]/+server.ts nutzt schon parsePositiveIntParam aus
api-helpers.ts. Der neue View-Endpoint hatte die Logik inline
nachgebaut — jetzt aufgeraeumt fuer Konsistenz.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
hsiegeln
2026-04-22 14:27:10 +02:00
parent 82d4348873
commit 1214b9e01d

View File

@@ -2,7 +2,7 @@ import type { RequestHandler } from './$types';
import { z } from 'zod';
import { error } from '@sveltejs/kit';
import { getDb } from '$lib/server/db';
import { validateBody } from '$lib/server/api-helpers';
import { validateBody, parsePositiveIntParam } from '$lib/server/api-helpers';
import { recordView } from '$lib/server/recipes/views';
const Schema = z.object({
@@ -10,10 +10,7 @@ const Schema = z.object({
});
export const POST: RequestHandler = async ({ params, request }) => {
const recipeId = Number(params.id);
if (!Number.isInteger(recipeId) || recipeId <= 0) {
error(400, { message: 'Invalid recipe id' });
}
const recipeId = parsePositiveIntParam(params.id, 'id');
const body = validateBody(await request.json().catch(() => null), Schema);
try {