Skip to main content

Overview

The Camion interface represents the core truck entity in Dashboard Backus. It tracks trucks throughout their journey from arrival to departure, including queue status, bay assignments, and alert states.

Camion Interface

Main entity that represents a truck in the system.
id
string
required
React internal key (stringified database ID)
id_db
number
required
Foreign key reference to viajes_camiones.id table — used for incident tracking
id_viaje
string
required
Unique trip identifier from viajes_camiones.id_viaje (text UNIQUE) — used for trip queries
placa
string
required
License plate number (tracto)
frotcom
string
Optional Frotcom fleet tracking identifier
propietario
string
required
Owner/operator name
fecha
string
required
Arrival date in “YYYY-MM-DD” format
hora
string
required
Arrival time in “HH:MM:SS” format
tipoOriginal
string
required
Original truck type as text from database (e.g., “Parihuelero”, “Jumbo”)
tipoCodigo
TipoCamion
required
Normalized truck type code: P | J | B | T | O
operacionCodigo
OperacionCodigo
required
Operation type code: C (Carga) | D (Descarga)
producto
string
required
Product type being loaded or unloaded (e.g., “Fardos”, “PP”, “PT”)
tiempoEntradaPatio
number
required
Timestamp in milliseconds when truck entered the yard (for local reference)
tiempoLlegadaCola
number
required
Timestamp in milliseconds when truck arrived at queue (traffic light)
estadoAlerta
EstadoAlerta
required
Current alert status based on time thresholds: verde | amarillo | rojo
maxAlertaReached
EstadoAlerta
required
Maximum alert level reached during the trip (never downgrades)
bahiaActual
string
Current bay assignment (e.g., “b1”, “b3”, “b10”)
turno
1 | 2 | 3
Shift number:
  • 1: 07:00–15:00
  • 2: 15:01–23:00
  • 3: 23:01–06:59
incidencias
number
Counter of registered incidents (maximum 3)
incidenciaAbierta
boolean
True if there’s an open incident without hora_fin — displays pulsing alert icon in bay

TipoCamion Type

Truck type classification codes.
export type TipoCamion = 'P' | 'J' | 'B' | 'T' | 'O';

Values

CodeTypeDescription
PParihueleroStandard flatbed truck with removable stakes
JJumboLarge capacity truck
BBi-trenBi-train (truck with two trailers)
TTolvaDump truck with hopper
OOtrosOther truck types not classified above

Type Mapping

The system normalizes database values to type codes:
const TIPO_MAP: Record<string, TipoCamion> = {
  parihuelero: 'P', 
  pariholero: 'P', 
  'pari-holero': 'P',
  jumbo: 'J',
  'bi-tren': 'B', 
  bitren: 'B',
  tolva: 'T',
  // Any unknown type defaults to 'O'
};

OperacionCodigo Type

Operation type classification.
export type OperacionCodigo = 'C' | 'D';

Values

CodeOperationDescription
CCargaLoading operation
DDescargaUnloading operation

Operation Detection

The system determines operation code from database text:
const opRaw: string = ((row.operacion as string | null) ?? '').toLowerCase();
const operacionCodigo: OperacionCodigo = opRaw.startsWith('c') ? 'C' : 'D';

EstadoAlerta Type

Traffic light alert status based on waiting time.
export type EstadoAlerta = 'verde' | 'amarillo' | 'rojo';

Values

StateColorDescription
verdeGreenNormal — within acceptable time range
amarilloYellowWarning — approaching time threshold
rojoRedCritical — exceeded maximum time threshold

Color Mapping

Helper function returns hex color codes:
export const getColorEstado = (estado: EstadoAlerta): string => {
  if (estado === 'rojo')     return '#ef4444';  // Tailwind red-500
  if (estado === 'amarillo') return '#eab308';  // Tailwind yellow-500
  return '#22c55e';                              // Tailwind green-500
};

Alert Thresholds

Alert states are calculated based on configurable time thresholds:
  • Verde: 0 to tiempoAmarillo minutes
  • Amarillo: tiempoAmarillo to tiempoRojo minutes
  • Rojo: tiempoRojo minutes and above
Default values are typically tiempoAmarillo: 30 and tiempoRojo: 45 minutes.

Rol Type

User role classification for access control.
export type Rol = 'admin' | 'cliente';

Values

RoleDescription
adminFull access — can modify configurations, register incidents, and view all data
clienteRead-only access — can view dashboard but cannot modify data

Usage Examples

Fetching Trucks from Queue

import { fetchCamionesCola } from './services/supabaseService';
import type { Camion } from './types';

const trucks: Camion[] = await fetchCamionesCola();
console.log(`Found ${trucks.length} trucks in queue`);

// Filter by truck type
const parihueleros = trucks.filter(t => t.tipoCodigo === 'P');

// Find trucks with open incidents
const withIncidents = trucks.filter(t => t.incidenciaAbierta);

// Check alert status
const critical = trucks.filter(t => t.estadoAlerta === 'rojo');

Type Guards

function isLoadingOperation(truck: Camion): boolean {
  return truck.operacionCodigo === 'C';
}

function canUseAllBays(truck: Camion): boolean {
  return ['P', 'J', 'B', 'T', 'O'].includes(truck.tipoCodigo);
}

function isParihuelero(truck: Camion): boolean {
  return truck.tipoCodigo === 'P';
}

Bay Compatibility Check

import { BAHIAS_CONFIG } from './Componentes/bahiasConfig';
import type { Camion, BahiaConfig } from './types';

function canTruckUseBay(truck: Camion, bayId: string): boolean {
  const bay: BahiaConfig = BAHIAS_CONFIG[bayId];
  if (!bay) return false;
  
  // Check truck type compatibility
  if (!bay.camionesPermitidos.includes(truck.tipoCodigo)) {
    return false;
  }
  
  // Check operation compatibility
  const tasks = bay.tareas[truck.operacionCodigo];
  return tasks.length > 0;
}

Display Truck Type Name

import { NOMBRES_TIPO_CAMION } from './Componentes/bahiasConfig';
import type { Camion } from './types';

function getTruckTypeName(truck: Camion): string {
  return NOMBRES_TIPO_CAMION[truck.tipoCodigo];
}

// Example:
const truck: Camion = { tipoCodigo: 'P', /* ... */ };
console.log(getTruckTypeName(truck)); // "Parihuelero"

Source

Defined in src/types.ts:3-30

Build docs developers (and LLMs) love