Public Bookings API
The Public Bookings API allows authenticated users to create bookings for active services. Unlike the admin bookings API, this is the customer-facing endpoint.Authentication
Requires valid user session (any authenticated user can create bookings).Create booking
Create a new booking for a service. Endpoint:POST /api/services/bookings
UUID of the service to book
Date in
YYYY-MM-DD formatTime in
HH:MM format (24-hour)Optional message from customer to provider
Validation & business logic
The endpoint performs comprehensive validation:1. Service validation
- Service must exist
- Service status must be
"active" - Provider (owner) must exist
2. Availability check
- Converts
bookingDateto day of week (0-6) - Queries
servicesAvailabilitytable for matching slots - Verifies
bookingTimefalls within an available slot - Checks
isAvailable = truefor the slot
3. Conflict detection
- Queries existing bookings for the same service, date, and time
- Rejects if another booking exists (no double-booking)
4. Automatic calculations
- Total price: Uses service’s
basePrice - Currency: Uses service’s
currency - Duration: Uses service’s
durationMinutes - Booking end time: Calculated as
bookingTime + durationMinutes
Response
Booking UUID
Service UUID
Provider (service owner) user ID
Customer (current user) ID
Booking date (YYYY-MM-DD)
Start time (HH:MM)
Calculated end time (HH:MM)
Service duration
Price in minor currency units (e.g., cents)
Currency code (e.g., “EUR”)
Always
"pending" for new bookingsCustomer’s message (if provided)
Booking creation timestamp
Error responses
Authentication required
Invalid JSON
Missing required fields
Service not found
Service not active
Time slot not available
Booking conflict
Booking workflow
- Customer submits booking → Status:
pending - Provider reviews (via admin API)
- Provider confirms → Status:
confirmed - Service delivered → Status:
completed
- Provider can
cancelorrejectbookings - Customer no-show → Status:
no_show
The booking status can only be changed by the provider through the admin API (
/api/admin/services/bookings). Customers cannot cancel or modify bookings through this endpoint.Day of week calculation
The availability system uses JavaScript’sDate.getDay():
- 0 = Sunday
- 1 = Monday
- 2 = Tuesday
- 3 = Wednesday
- 4 = Thursday
- 5 = Friday
- 6 = Saturday
2024-12-15 (Sunday) → dayOfWeek = 0
Time slot matching
A booking time is valid if:- Slot:
09:00-17:00 - Booking time
14:00→ Valid ✓ - Booking time
18:00→ Invalid ✗
Implementation reference
Source:/src/pages/api/services/bookings.ts
Key implementation details:
- Session extraction from
locals.sessionorlocals.user - Drizzle ORM queries for validation
- Date/time calculations using JavaScript Date
- Conflict detection with
eq()andand()operators - Automatic field population from service data