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

@@ -97,14 +97,24 @@ export async function POST(request: NextRequest) {
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 = typeMap[type?.toLowerCase()] || type || 'INDOOR';
const mappedStatus = statusMap[status?.toLowerCase()] || status || 'AVAILABLE';
// Validate required fields
if (!siteId || !name || pricePerHour === undefined) {
if (!siteId || !name || price === undefined) {
return NextResponse.json(
{ error: 'Missing required fields: siteId, name, pricePerHour' },
{ status: 400 }
@@ -138,12 +148,13 @@ export async function POST(request: NextRequest) {
data: {
siteId,
name,
type: type || 'INDOOR',
status: status || 'AVAILABLE',
pricePerHour,
type: mappedType,
status: mappedStatus,
pricePerHour: price,
description: description || null,
features: features || [],
displayOrder: displayOrder ?? 0,
isOpenPlay: isOpenPlay ?? false,
isActive: isActive ?? true,
},
include: {