When a conductor accepts a ride, the server executes three sequential database operations: it updates the ride record, creates a dedicated chat thread for the trip, and registers both participants as thread members. Each step is guarded by a rollback — if thread creation fails, the ride is reverted toDocumentation 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.
"solicitado"; if member insertion fails, the thread is deleted and the ride is reverted as well. This keeps the database consistent even under partial failures.
Access: requires the conductor role. The route is protected by authMiddleware followed by roleMiddleware(['conductor']).
Request
Bearer JWT from Supabase Auth. The authenticated user must have
rol = "conductor" in public.perfiles.UUID of the ride to accept. The ride must currently be in state
"solicitado".Example request body
Transactional flow
Fetch the viaje
The server looks up the ride by
viajeId using findViajeById. If no record is found, it returns 404. This also loads pasajero_id, which is needed for thread member insertion later.Validate state
If
viaje.estado !== 'solicitado', the request is rejected with 400 and the current state is included in the error message. A ride that is already "aceptado", "en_curso", "finalizado", or "cancelado" cannot be accepted again.Update the viaje
Sets
conductor_id to the authenticated conductor’s user ID, changes estado to "aceptado", and stamps updated_at with the current UTC timestamp.Create the chat thread
Inserts a new row into
public.threads with the viaje_id reference. If this insert fails, the server rolls back step 3 — resetting conductor_id to null and estado to "solicitado" — then returns 500.Response 200
The updated ride record after acceptance.
Chat thread details created during this operation.
Error cases
| HTTP status | Cause |
|---|---|
400 | viajeId was not provided in the request body |
404 | No ride found with the given viajeId |
400 | Ride exists but estado is not "solicitado" |
500 | Thread creation in public.threads failed — viaje rolled back to "solicitado" |
500 | Thread member insertion in public.thread_members failed — thread deleted and viaje rolled back |