From 1214b9e01df5acae1ef734cd4008a2b25ca5fa4f Mon Sep 17 00:00:00 2001 From: hsiegeln <37154749+hsiegeln@users.noreply.github.com> Date: Wed, 22 Apr 2026 14:27:10 +0200 Subject: [PATCH] refactor(api): parsePositiveIntParam fuer view-endpoint MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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) --- src/routes/api/recipes/[id]/view/+server.ts | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/src/routes/api/recipes/[id]/view/+server.ts b/src/routes/api/recipes/[id]/view/+server.ts index ef309de..da8b645 100644 --- a/src/routes/api/recipes/[id]/view/+server.ts +++ b/src/routes/api/recipes/[id]/view/+server.ts @@ -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 {