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
string
required
UUID of the service to book
string
required
Date in
YYYY-MM-DD formatstring
required
Time in
HH:MM format (24-hour)text
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
string
Booking UUID
string
Service UUID
string
Provider (service owner) user ID
string
Customer (current user) ID
string
Booking date (YYYY-MM-DD)
string
Start time (HH:MM)
string
Calculated end time (HH:MM)
number
Service duration
number
Price in minor currency units (e.g., cents)
string
Currency code (e.g., “EUR”)
string
Always
"pending" for new bookingstext
Customer’s message (if provided)
timestamp
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