Overview
Queue operations handle fetching trucks currently waiting in the “En cola” state from theviajes_camiones table. The main function maps raw database records to the internal Camion type used throughout the React application.
fetchCamionesCola
Retrieves all trucks currently in the queue, ordered by arrival time.Return Type
Array of trucks in queue, ordered by
hora_llegada ascending. Returns empty array on error.Query Details
The function performs the following query:Type Mapping
The raw database records are transformed to the internalCamion type:
String representation of the primary key
Integer primary key from database
Trip identifier (falls back to
id if null)License plate from
tracto column (”—” if null)Frotcom tracking ID (undefined if null)
Owner name (”—” if null)
Arrival date
Arrival time from
hora_llegadaRaw truck type from
tipo_unidad columnNormalized truck type code: ‘P’ (pari-holero), ‘J’ (jumbo), ‘B’ (bi-tren), ‘T’ (tolva), ‘O’ (other)
‘C’ for “Carga” (loading), ‘D’ for “Descarga” (unloading)
Product type from
tipo_carga (if loading) or tipo_descarga (if unloading)Timestamp in milliseconds when truck entered the yard
Timestamp in milliseconds when truck joined the queue
Alert status (always ‘verde’ for queued trucks)
Maximum alert level reached (always ‘verde’ initially)
Current bay assignment (undefined if not assigned)
Count of incidents from
conteo_incidencias (0 if null)Whether truck has an open incident (always false in queue)
Truck Type Mapping
Thetipo_unidad field is normalized using this mapping:
| Database Value | Code | Type |
|---|---|---|
| ”parihuelero”, “pariholero”, “pari-holero” | P | Pari-holero |
| ”jumbo” | J | Jumbo |
| ”bi-tren”, “bitren” | B | Bi-tren |
| ”tolva” | T | Tolva |
| (any other) | O | Other |
Time Conversion
Thehora_llegada field (Postgres TIME format “HH:MM:SS”) is converted to a JavaScript timestamp:
Example Usage
Real-world Example
Error Handling
The function returns an empty array on error and logs to console:Related Functions
Incident Operations
Query and manage incidents for queued trucks
Trip Operations
Move trucks from queue to bays
