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:
@@ -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: {
|
||||
|
||||
@@ -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: {
|
||||
|
||||
Reference in New Issue
Block a user