Orders con endpoints para monitorizacion

This commit is contained in:
2026-02-25 12:20:52 +01:00
parent c416114c50
commit 02c80cd503
16 changed files with 373 additions and 63 deletions

View File

@@ -72,31 +72,41 @@ export class OrderRepository {
/**
* Busqueda según la id de RabbitMq
*/
public async getOrderByQueueId<T>(data: { correlation_id: string }, pool?: PoolClient) {
public async getOrderByQueueId<T>(data: { message_id: string }, pool?: PoolClient) {
const query = `
SELECT * FROM order_tracking
WHERE correlation_id = $1
`
const values = [data.correlation_id]
const values = [data.message_id]
const queryPromise = this.pgClient.query<OrderTracking<T>>(query, values)
const result = await this.getFirst(queryPromise);
return result
}
/**
*/
* Operaciones que no han concluido con filtros de limit, offset y start
* @param options ()
* @returns
*/
public async getPendingOrders<T>(options?: {
limit?: number
limit?: number,
offset?: number,
start?: number // id de inicio
}) {
const client = await this.pgClient.connect();
const offsetFragment = (options?.offset != undefined) ? `OFFSET ${options?.offset}` : ""
const limitFragment = (options?.limit != undefined) ? `LIMIT ${options?.limit}` : ""
const startFragment = (options?.start != undefined) ? `AND id >= ${options?.start}` : ""
const query = `
SELECT * FROM order_tracking
WHERE finish_date IS NULL
WHERE finish_date IS NULL
${startFragment}
ORDER BY start_date ASC
${offsetFragment}
${limitFragment}
`
if (options?.limit != undefined) {
}
const values: string[] = []
const queryPromise = client.query<OrderTracking<T>>(query, values)
const result = await this.getAll(queryPromise)
@@ -104,7 +114,7 @@ export class OrderRepository {
return result
}
public async createOrder(data: CreateOrderDTO) {
public async createOrder<T extends any>(data: CreateOrderDTO): Promise<Result<string, OrderTracking<T>>> {
const client = await this.pgClient.connect();
await client.query("BEGIN")
const query = `
@@ -114,7 +124,9 @@ export class OrderRepository {
routing_key,
order_type,
payload,
status
status,
webhook_host,
webhook_endpoint
)
VALUES (
$1, -- correlation_id
@@ -122,12 +134,23 @@ export class OrderRepository {
$3, -- routing_key
$4, -- order_type (ej: 'activate')
$5, -- payload (json object)
'pending'
'pending',
$6, -- webhook_host,
$7 -- webhook_endpoint
)
RETURNING id, correlation_id, status, start_date;
RETURNING
id,
correlation_id,
exchange,
routing_key,
order_type,
payload,
status,
webhook_host,
webhook_endpoint
`
const values = [data.correlation_id, data.exchange, data.routing_key, data.order_type, data.payload]
const queryPromise = client.query<{ id: number, correlation_id: string, status: string, start_date: string }>(query, values)
const values = [data.correlation_id, data.exchange, data.routing_key, data.order_type, data.payload, data.webhook_host, data.webhook_endpoint]
const queryPromise = client.query<OrderTracking<T>>(query, values)
// TODO comprobar si start_date convierte a Date por defecto, añadir enum de status
const result = await this.getFirst(queryPromise)