Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/DavidCevallos15/Crucidrive---APP/llms.txt

Use this file to discover all available pages before exploring further.

Both the passenger and the conductor can move a ride through its lifecycle, but only if they are actually participants of that specific ride. Before applying any update, the server verifies that the requesting user’s ID matches either pasajero_id or conductor_id on the record, and that the requested transition is valid given the ride’s current state. Attempts to skip states or cancel a completed ride are rejected. Access: any authenticated user (authMiddleware only — no role restriction), provided they are a participant of the ride being updated.

Path parameter

id
string
required
UUID of the ride whose status should be changed. Passed as a URL segment: PATCH /api/viajes/:id/estado.

Request body

estado
string
required
The target state to transition to. Must be one of: "en_curso", "finalizado", or "cancelado". Any other value returns a 400 before the database is queried.

Example request body

{ "estado": "en_curso" }

State transition rules

The server enforces the following valid transitions. Any request that violates these rules returns 400 with a descriptive message.
Target stateRequired current stateWho can set
en_cursoaceptadoEither participant
finalizadoen_cursoEither participant
canceladosolicitado, aceptado, or en_cursoEither participant
A ride in state finalizado or cancelado cannot be cancelled — the server returns 400 with the current state in the error message.

Response 200

The full updated viaje record is returned after a successful transition.
id
string
UUID of the ride.
pasajero_id
string
UUID of the passenger participant.
conductor_id
string
UUID of the conductor participant (set when the ride was accepted).
estado
string
The new state of the ride: "en_curso", "finalizado", or "cancelado".
tarifa
number
Ride fare in USD (1.50).
updated_at
string
ISO 8601 timestamp stamped by the server at the time of this update.

Participant validation

Before any state change is applied, cambiarEstadoViaje checks:
if (viaje.pasajero_id !== userId && viaje.conductor_id !== userId) {
  return errorResponse(res, 403, 'Acceso denegado. No eres participante de este viaje.');
}
userId is req.user.id — the UUID from the validated Supabase JWT. A user who is not listed as either the passenger or the conductor on the record receives a 403, regardless of their platform role.

Error cases

HTTP statusCause
400estado is missing or not one of the three valid values
404No ride found with the given :id
403Authenticated user is not pasajero_id or conductor_id of this ride
400Transition is invalid — e.g. trying to set en_curso when ride is still solicitado
400Trying to cancel a ride already in finalizado or cancelado state

curl example — transition to en_curso

curl -X PATCH https://api.crucidrive.local/api/viajes/c3d4e5f6-0000-0000-0000-aabbccddeeff/estado \
  -H "Authorization: Bearer <your_access_token>" \
  -H "Content-Type: application/json" \
  -d '{ "estado": "en_curso" }'
{
  "status": "success",
  "message": "Estado del viaje actualizado a \"en_curso\" correctamente.",
  "data": {
    "id": "c3d4e5f6-0000-0000-0000-aabbccddeeff",
    "pasajero_id": "a1b2c3d4-0000-0000-0000-111122223333",
    "conductor_id": "b9c8d7e6-0000-0000-0000-999988887777",
    "origen": "POINT(-80.5432 -1.0448)",
    "destino": "POINT(-80.5485 -1.047)",
    "estado": "en_curso",
    "tarifa": 1.50,
    "created_at": "2024-11-15T14:22:00.000Z",
    "updated_at": "2024-11-15T14:30:45.000Z"
  }
}

Build docs developers (and LLMs) love