92 lines
2.3 KiB
TypeScript
92 lines
2.3 KiB
TypeScript
/**
|
|
* LogDespacho Entity
|
|
* ERP Transportistas
|
|
*
|
|
* Audit log of all dispatch actions.
|
|
* Module: MAI-005 Despacho
|
|
* Adapted from: erp-mecanicas-diesel MMD-011 DispatchLog
|
|
*/
|
|
|
|
import {
|
|
Entity,
|
|
PrimaryGeneratedColumn,
|
|
Column,
|
|
Index,
|
|
} from 'typeorm';
|
|
|
|
export enum AccionDespacho {
|
|
CREATED = 'created',
|
|
ASSIGNED = 'assigned',
|
|
REASSIGNED = 'reassigned',
|
|
REJECTED = 'rejected',
|
|
ESCALATED = 'escalated',
|
|
CANCELLED = 'cancelled',
|
|
ACKNOWLEDGED = 'acknowledged',
|
|
COMPLETED = 'completed',
|
|
}
|
|
|
|
@Entity({ name: 'log_despacho', schema: 'despacho' })
|
|
@Index('idx_log_despacho_tenant', ['tenantId'])
|
|
@Index('idx_log_despacho_viaje', ['tenantId', 'viajeId'])
|
|
@Index('idx_log_despacho_fecha', ['tenantId', 'ejecutadoEn'])
|
|
@Index('idx_log_despacho_accion', ['tenantId', 'accion'])
|
|
export class LogDespacho {
|
|
@PrimaryGeneratedColumn('uuid')
|
|
id: string;
|
|
|
|
@Column({ name: 'tenant_id', type: 'uuid' })
|
|
tenantId: string;
|
|
|
|
// Viaje reference (FK a transport.viajes) - instead of incident
|
|
@Column({ name: 'viaje_id', type: 'uuid' })
|
|
viajeId: string;
|
|
|
|
// Action
|
|
@Column({
|
|
type: 'varchar',
|
|
length: 20,
|
|
})
|
|
accion: AccionDespacho;
|
|
|
|
// Unit/Operador changes - instead of technician
|
|
@Column({ name: 'desde_unidad_id', type: 'uuid', nullable: true })
|
|
desdeUnidadId?: string;
|
|
|
|
@Column({ name: 'hacia_unidad_id', type: 'uuid', nullable: true })
|
|
haciaUnidadId?: string;
|
|
|
|
@Column({ name: 'desde_operador_id', type: 'uuid', nullable: true })
|
|
desdeOperadorId?: string;
|
|
|
|
@Column({ name: 'hacia_operador_id', type: 'uuid', nullable: true })
|
|
haciaOperadorId?: string;
|
|
|
|
// Context
|
|
@Column({ type: 'text', nullable: true })
|
|
razon?: string;
|
|
|
|
@Column({ type: 'boolean', default: false })
|
|
automatizado: boolean;
|
|
|
|
@Column({ name: 'regla_id', type: 'uuid', nullable: true })
|
|
reglaId?: string;
|
|
|
|
@Column({ name: 'escalamiento_id', type: 'uuid', nullable: true })
|
|
escalamientoId?: string;
|
|
|
|
// Response times
|
|
@Column({ name: 'tiempo_respuesta_segundos', type: 'integer', nullable: true })
|
|
tiempoRespuestaSegundos?: number;
|
|
|
|
// Actor
|
|
@Column({ name: 'ejecutado_por', type: 'uuid', nullable: true })
|
|
ejecutadoPor?: string;
|
|
|
|
@Column({ name: 'ejecutado_en', type: 'timestamptz', default: () => 'NOW()' })
|
|
ejecutadoEn: Date;
|
|
|
|
// Extra data
|
|
@Column({ type: 'jsonb', default: {} })
|
|
metadata: Record<string, any>;
|
|
}
|