Implement booking availability and pricing core
This commit is contained in:
23
src/app/api/booking/search/route.ts
Normal file
23
src/app/api/booking/search/route.ts
Normal file
@@ -0,0 +1,23 @@
|
||||
import { NextResponse } from 'next/server';
|
||||
import { searchBookings } from '@/lib/booking';
|
||||
|
||||
function parseNumber(value: string | null, fallback: number) {
|
||||
if (value === null || value === '') return fallback;
|
||||
const parsed = Number(value);
|
||||
return Number.isFinite(parsed) ? parsed : fallback;
|
||||
}
|
||||
|
||||
export function GET(request: Request) {
|
||||
const url = new URL(request.url);
|
||||
const result = searchBookings({
|
||||
arrivalDate: url.searchParams.get('arrivalDate') ?? undefined,
|
||||
departureDate: url.searchParams.get('departureDate') ?? undefined,
|
||||
adults: parseNumber(url.searchParams.get('adults'), 2),
|
||||
children: parseNumber(url.searchParams.get('children'), 0),
|
||||
pets: parseNumber(url.searchParams.get('pets'), 0),
|
||||
location: url.searchParams.get('location') ?? undefined,
|
||||
propertySlug: url.searchParams.get('propertySlug') ?? undefined,
|
||||
});
|
||||
|
||||
return NextResponse.json(result);
|
||||
}
|
||||
Reference in New Issue
Block a user