Orders en todas las etapas
This commit is contained in:
@@ -16,43 +16,47 @@ export class CheckObjeniousRequests {
|
||||
* TODO: meter a una funcion a parte task con los 3 pasos
|
||||
*/
|
||||
public async getPendingOperations() {
|
||||
// 1. Se obtienen todas las operaciones pendientes de la BDD
|
||||
const pendingOperations = await this.operationsRepository.getPendingOperations()
|
||||
|
||||
|
||||
if (pendingOperations.error != undefined) {
|
||||
throw new Error("Error obteniendo las tareas pendientes " + pendingOperations.error)
|
||||
}
|
||||
|
||||
if (pendingOperations.data == undefined || pendingOperations.data.length == 0) {
|
||||
//Nada pendiente
|
||||
console.log("[cron] No hay operaciones pendientes de Objenious")
|
||||
return;
|
||||
}
|
||||
|
||||
// 2. Clasificación de las tareas pendientes
|
||||
// Erroneas => no se les ha dado un request_id, no se pueden comprobar
|
||||
const erroneas = pendingOperations.data
|
||||
.filter((e) => e.request_id == undefined)
|
||||
|
||||
// Todas las validas
|
||||
const operacionesValidas = pendingOperations.data
|
||||
.filter((e) => e.request_id != undefined)
|
||||
|
||||
// Validas sin MassId
|
||||
const solicitarMassId = operacionesValidas
|
||||
.filter((e) => e.mass_action_id == undefined)
|
||||
|
||||
// Validas con MassId
|
||||
const consultarEstado = pendingOperations.data
|
||||
.filter(e => e.mass_action_id != undefined)
|
||||
// TODO: Validas sin/con massID que lleven mucho tiempo sin actualizarse
|
||||
|
||||
console.log("[cron] Solicitando mass id para", solicitarMassId.map(e => e.id))
|
||||
|
||||
const newMassActions = await this.getMassIdFromRequest(solicitarMassId)
|
||||
|
||||
const merged = [...newMassActions || [], ...consultarEstado]
|
||||
|
||||
console.log("[cron] Solicitando status para", merged.map(e => e.id))
|
||||
|
||||
const result = await this.getMassActionsStatus(merged)
|
||||
}
|
||||
|
||||
/**
|
||||
* Para una lista de operaciones **con mass_action_id** se comprueba si han tenido alguna actualizacion
|
||||
* Devuelve el numero de operaciones comprobadas.
|
||||
*/
|
||||
private async getMassActionsStatus(requestList: ObjeniousOperation[]) {
|
||||
if (requestList.length == 0) return;
|
||||
if (requestList.length == 0) return 0;
|
||||
|
||||
const operationsList = structuredClone(requestList)
|
||||
const PATH = "/actions/massActions/"
|
||||
@@ -123,6 +127,14 @@ export class CheckObjeniousRequests {
|
||||
console.log("[i] lineData", lineData.content[0])
|
||||
const msisdn = lineData.content[0].identifier.msisdn
|
||||
|
||||
if (originalAction.correlation_id != undefined) {
|
||||
this.orderRepository.finishOrder({ correlation_id: originalAction.correlation_id })
|
||||
.then(e => console.log("[o] Finalizada order", e))
|
||||
.catch(e => {
|
||||
console.error("[x] Error finalizando la order ", e)
|
||||
console.error(e)
|
||||
})
|
||||
}
|
||||
this.notifyFinalization({
|
||||
...originalAction,
|
||||
msisdn
|
||||
|
||||
Reference in New Issue
Block a user