templates2.Booking.Next/app/api/availability/route.ts
w4c-templates 6a0c2e88d2
Some checks are pending
CI / quality (push) Waiting to run
chore(template): publish Booking.Next
2026-10-11 23:27:02 +03:00

24 lines
922 B
TypeScript

import { NextResponse } from 'next/server';
import { getAvailableSlots } from '@/lib/server/booking';
export const dynamic = 'force-dynamic';
/**
* GET /api/availability?serviceId=&staffId=&date=
* Server-computed bookable slots (past and taken slots already excluded). All datetimes are UTC
* ISO strings; `timeZone` tells the client how to display them.
*/
export async function GET(request: Request) {
const { searchParams } = new URL(request.url);
const serviceId = searchParams.get('serviceId');
const staffId = searchParams.get('staffId') || null;
const date = searchParams.get('date') || undefined;
if (!serviceId) return NextResponse.json({ error: 'serviceId is required.' }, { status: 400 });
const result = await getAvailableSlots({ serviceId, staffId, date });
if (!result) return NextResponse.json({ error: 'Service not found.' }, { status: 404 });
return NextResponse.json(result);
}