fix: handle isOpenPlay and map form values to Prisma enums in court API

- Add isOpenPlay field to POST and PUT routes
- Accept both hourlyRate and pricePerHour (form vs API naming)
- Map lowercase type/status from form to uppercase Prisma enums

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Ivan
2026-03-03 23:21:36 +00:00
parent 296491d0b9
commit da8a730867
2 changed files with 29 additions and 7 deletions

View File

@@ -125,23 +125,34 @@ export async function PUT(
type,
status,
pricePerHour,
hourlyRate,
description,
features,
displayOrder,
isActive,
isOpenPlay,
} = body;
const price = pricePerHour ?? hourlyRate;
// Map lowercase form values to Prisma enum values
const typeMap: Record<string, string> = { indoor: 'INDOOR', outdoor: 'OUTDOOR', covered: 'COVERED' };
const statusMap: Record<string, string> = { active: 'AVAILABLE', maintenance: 'MAINTENANCE', inactive: 'CLOSED' };
const mappedType = type ? (typeMap[type.toLowerCase()] || type) : undefined;
const mappedStatus = status ? (statusMap[status.toLowerCase()] || status) : undefined;
const court = await db.court.update({
where: { id },
data: {
...(name !== undefined && { name }),
...(type !== undefined && { type }),
...(status !== undefined && { status }),
...(pricePerHour !== undefined && { pricePerHour }),
...(mappedType !== undefined && { type: mappedType }),
...(mappedStatus !== undefined && { status: mappedStatus }),
...(price !== undefined && { pricePerHour: price }),
...(description !== undefined && { description }),
...(features !== undefined && { features }),
...(displayOrder !== undefined && { displayOrder }),
...(isActive !== undefined && { isActive }),
...(isOpenPlay !== undefined && { isOpenPlay }),
},
include: {
site: {