Introduction
ThesupabaseService.ts module is the single source of truth for all data operations in Dashboard Backus. It provides a clean, type-safe interface to:
- SELECT from Supabase views and tables (queue, dashboard panels)
- INSERT incidents directly into the
incidenciastable - UPDATE trip records in
viajes_camiones(bay assignment, status, departure time) - Realtime subscriptions via Postgres change events
Architecture
All data flows through this service to ensure consistency and maintainability. The service integrates with:- Tables:
viajes_camiones,incidencias,usuarios - Views:
vista_unidad_prioridad,vista_dashboard_turnos,vista_promedio_patio_neto - Types: Defined in
src/types.tsfor full TypeScript safety
Environment Configuration
Table and view names can be overridden via environment variables:Function Categories
Queue Operations
Fetch and manage trucks in the queue
Incident Operations
Open, close, and query incidents
Trip Operations
Update bay assignments and mark departures
Dashboard Panels
Fetch priority units, shift counts, and average times
Core Types
UsuarioLogin
Authenticated user object returned byloginUsuario.
User primary key
User email address
User role for authorization
User display name (may be null)
IncidenciaRow
Incident record structure.Primary key (auto-generated)
Foreign key to
viajes_camiones.idStart time in “HH:MM:SS” format (Postgres TIME)
End time in “HH:MM:SS” format (null if incident is still open)
Authentication
TheloginUsuario function provides MD5-based authentication against the usuarios table, using MD5 hashing (RFC 1321) to match PostgreSQL’s md5() function. See the Trip Operations documentation for implementation details.
Error Handling
All functions use a centralized error handler that:- Logs errors to the console with context
- Returns
null,false, or empty arrays on failure - Never throws exceptions (safe for UI consumption)
Utility Functions
intervalAMinutos
Converts PostgreSQL interval strings to minutes.Postgres interval (e.g., “02:30:00”, “1 day 02:30:00”, “-01:15:00”)
Total minutes (negative for intervals like night shift crossovers)
"HH:MM:SS"- Standard format"HH:MM:SS.mmm"- With milliseconds"-HH:MM:SS"- Negative intervals"1 day 02:30:00"- Multi-day intervals"HH:MM:SS+00"- With timezone offset (stripped)
intervalATexto
Formats PostgreSQL intervals as human-readable text.Postgres interval
Formatted string (“Xh Ym”, “Ym”, or ”< 1m”)
Next Steps
Queue Operations
Learn how to fetch and manage the truck queue
Incident Operations
Understand incident lifecycle management
