Adds parseId helper in src/server/lib/params.ts and applies it across all route files so non-positive-integer IDs return 400 instead of silently passing NaN to services. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
10 lines
287 B
TypeScript
10 lines
287 B
TypeScript
/**
|
|
* Parse a route parameter as a positive integer ID.
|
|
* Returns the number if valid, or null if the string is not a positive integer.
|
|
*/
|
|
export function parseId(raw: string): number | null {
|
|
const id = Number(raw);
|
|
if (!Number.isInteger(id) || id <= 0) return null;
|
|
return id;
|
|
}
|