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
This commit is contained in:
parent
f6737ee19c
commit
73c2fae7b8
1 changed files with 26 additions and 3 deletions
|
|
@ -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<any>(event.request)
|
||||
const body = await parseRequestBody<ProjectUpdateBody>(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<any>(event.request)
|
||||
const body = await parseRequestBody<ProjectUpdateBody>(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) {
|
||||
|
|
|
|||
Loading…
Reference in a new issue