TheDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/JuanSerna14/Final-lenguaje-Avanzado/llms.txt
Use this file to discover all available pages before exploring further.
/api/reservas endpoints manage bookings (reservas) against sports courts. Both routes are protected by the verifyToken middleware and require a valid JWT Bearer token. The POST endpoint includes server-side overlap detection — before inserting a new reservation it calls reservasRepository.existeSolapamiento(), which uses PostgreSQL’s OVERLAPS operator to detect time-range conflicts on the same court and date. If a conflict is found, the API returns 409 rather than allowing a double-booking.
GET /api/reservas
Returns all reservations ordered by date and start time (ORDER BY r.fecha ASC, r.hora_inicio ASC). The query uses a JOIN on the canchas table, so each reservation object includes cancha_nombre alongside the foreign key cancha_id.
Authentication
RequiresAuthorization: Bearer <accessToken>.
Example request
Response — 200 OK
Always
true on a successful response.Error codes
| Code | Meaning |
|---|---|
401 | Missing or invalid Bearer token |
500 | Internal server error — { ok: false, mensaje: "Error al obtener las reservas" } |
POST /api/reservas
Creates a new court reservation. The request body is validated with the Zod schemaCrearReservaSchema from reservas.types.ts. After validation the service checks that the referenced court exists, then verifies there are no overlapping non-cancelled reservations before inserting.
Authentication
RequiresAuthorization: Bearer <accessToken>.
Request body
The ID of the court to book. Must be a positive integer. The API will return
404 if no court with this ID exists.Reservation date in
YYYY-MM-DD format (e.g. "2025-06-15"). Validated with the regex /^\d{4}-\d{2}-\d{2}$/.Start time in
HH:MM format (e.g. "09:00"). Validated with the regex /^\d{2}:\d{2}$/.End time in
HH:MM format (e.g. "11:00"). Validated with the regex /^\d{2}:\d{2}$/. Must be after hora_inicio — enforced by the database CHECK constraint hora_valida (hora_fin > hora_inicio).Full name of the customer. Must be at least 1 character.
Customer contact number as a string. Must be at least 7 characters.
Channel that originated the booking. Accepted values:
"whatsapp" or "interfaz". Defaults to "interfaz" if omitted.Example request
Response — 201 Created
Always
true on successful creation.The newly inserted reservation returned from
RETURNING *. Includes the auto-assigned id, estado (defaulted to pendiente), and created_at.Response — 400 Bad Request (Zod validation failure)
Returned when the body failsCrearReservaSchema Zod parsing. Unlike POST /api/canchas, the errores array contains raw Zod ZodIssue objects (not remapped to {campo, problema}):
Error codes
| Code | Meaning |
|---|---|
400 | Request body failed Zod validation — { ok: false, mensaje: "Error de validación", errores: [<ZodIssue>, ...] } |
401 | Missing or invalid Bearer token |
404 | The referenced cancha_id does not exist — { ok: false, mensaje: "Cancha con ID <id> no encontrada" } |
409 | Time slot conflict — { ok: false, mensaje: "La cancha ya se encuentra reservada de HH:MM a HH:MM" } |
500 | Internal server error |
Conflict detection
Before inserting, the API calls PostgreSQL’s
reservasRepository.existeSolapamiento(cancha_id, fecha, hora_inicio, hora_fin). This runs the following PostgreSQL query:OVERLAPS operator returns true when two time ranges share any moment, so even a partial overlap (e.g. a new booking from 10:00–12:00 against an existing 09:00–11:00 booking) is detected and rejected. Reservations with estado = 'cancelada' are excluded from the check and do not block new bookings.Reservation states
Reservations are created withestado = 'pendiente' by default (the INSERT statement omits the estado column, so the database default applies). The estado column has a CHECK constraint that allows exactly three values:
| Estado | Meaning |
|---|---|
pendiente | Booking received, awaiting confirmation. Default on creation. |
confirmada | Booking has been confirmed by staff or the system. |
cancelada | Booking has been cancelled. Excluded from overlap checks, freeing the slot. |
Courts API
Manage the courts that can be reserved, including listing, fetching by ID, and creation.
API Overview
All PitchPro endpoints at a glance with base URL, auth format, and error conventions.
Authentication Guide
Learn how to obtain and refresh Bearer tokens used on all reservation requests.