From 73c2fae7b8958003534986980851152b39faba3f Mon Sep 17 00:00:00 2001 From: Justin Edmund Date: Sun, 23 Nov 2025 05:16:55 -0800 Subject: [PATCH] fix: complete API route type safety improvements - add ProjectUpdateBody interface for partial updates - use Prisma.ProjectUpdateInput for update operations - replace all remaining any types in projects endpoints - consistent use of proper types across all API routes --- src/routes/api/projects/[id]/+server.ts | 29 ++++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/src/routes/api/projects/[id]/+server.ts b/src/routes/api/projects/[id]/+server.ts index b136589..4b1ec87 100644 --- a/src/routes/api/projects/[id]/+server.ts +++ b/src/routes/api/projects/[id]/+server.ts @@ -1,4 +1,5 @@ import type { RequestHandler } from './$types' +import type { Prisma } from '@prisma/client' import { prisma } from '$lib/server/database' import { jsonResponse, @@ -15,6 +16,28 @@ import { type MediaUsageReference } from '$lib/server/media-usage.js' +// Type for project update request body (partial of ProjectCreateBody) +interface ProjectUpdateBody { + title?: string + subtitle?: string + description?: string + year?: number + client?: string + role?: string + featuredImage?: string + logoUrl?: string + gallery?: Prisma.JsonValue + externalUrl?: string + caseStudyContent?: Prisma.JsonValue + backgroundColor?: string + highlightColor?: string + projectType?: string + displayOrder?: number + status?: string + password?: string | null + slug?: string +} + // GET /api/projects/[id] - Get a single project export const GET: RequestHandler = async (event) => { const id = parseInt(event.params.id) @@ -51,7 +74,7 @@ export const PUT: RequestHandler = async (event) => { } try { - const body = await parseRequestBody(event.request) + const body = await parseRequestBody(event.request) if (!body) { return errorResponse('Invalid request body', 400) } @@ -191,7 +214,7 @@ export const PATCH: RequestHandler = async (event) => { } try { - const body = await parseRequestBody(event.request) + const body = await parseRequestBody(event.request) if (!body) { return errorResponse('Invalid request body', 400) } @@ -214,7 +237,7 @@ export const PATCH: RequestHandler = async (event) => { } // Build update data object with only provided fields - const updateData: any = {} + const updateData: Prisma.ProjectUpdateInput = {} // Handle status update specially if (body.status !== undefined) {