Files
sf-sim/packages/sim-shared/domain/Order.ts
2026-04-15 15:11:13 +02:00

98 lines
2.1 KiB
TypeScript

// Reemplaza al enum OrderStatus
export type OrderStatus =
| 'pending'
| 'running'
| 'finished'
| 'failed'
| 'dlx';
// Reemplaza al enum OrderTypes
export type OrderType =
| 'activate'
| 'preactivate'
| 'cancel'
| 'pause'
| 'reactivate'
| 'unknown';
export const OrderTypeOptions = new Set<OrderType>([
'activate',
'preactivate',
'cancel',
'pause',
'reactivate',
'unknown'
])
// Interfaz para la tabla order_tracking
export interface OrderTracking<T> {
id: number;
correlation_id: string;
exchange?: string | null;
routing_key?: string | null;
order_type: OrderType;
payload?: Record<string, T> | null; // Por no especificar el tipo del json hasta que no se cree
status: OrderStatus;
retry_count: number;
error_message?: string | null;
error_stacktrace?: string | null;
/* TODO: Importante decidir si trabajar con fecha y tener que crear los objetos o seguir como string */
start_date: string | Date;
update_date: string | Date;
finish_date?: string | Date | null;
// desde la 1.1.0
webhook_host?: string | null;
webhook_endpoint?: string | null;
}
// Interfaz para la tabla order_history
export interface OrderHistory {
id: number;
order_id: number;
previous_status: OrderStatus;
new_status: OrderStatus;
change_reason?: string | null;
change_date: Date;
}
// Tipo útil para la creación (Omitiendo campos generados por la DB)
export type CreateOrderDTO = Pick<
OrderTracking<any>, // Aqui realmente no importan los campos
'correlation_id' | 'exchange' | 'routing_key' | 'order_type' | 'payload' | 'webhook_host' | 'webhook_endpoint'
>;
type IdOrCorrelationID =
(
{ id: number, correlation_id?: never } |
{ id?: never, correlation_id: string }
)
export type UpdateOrderDTO =
IdOrCorrelationID
&
{
new_status: OrderStatus,
reason?: string
}
export type FinishOrderDTO =
IdOrCorrelationID
&
{
reason?: string,
end_date?: Date
}
export type ErrorOrderDTO =
IdOrCorrelationID
&
{
status: "failed" | "dlx",
reason: string,
error?: string,
stackTrace?: string
}