Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 9d63d23754 |
@@ -10,7 +10,7 @@ import { env } from './env/index.js';
|
|||||||
export const pgPoolIntranet = new Pool({
|
export const pgPoolIntranet = new Pool({
|
||||||
user: env.POSTGRES_USER,
|
user: env.POSTGRES_USER,
|
||||||
host: env.POSTGRES_HOST,
|
host: env.POSTGRES_HOST,
|
||||||
database: "postgres",
|
database: "intranet",
|
||||||
password: env.POSTGRES_PASSWORD,
|
password: env.POSTGRES_PASSWORD,
|
||||||
port: Number(env.POSTGRES_PORT) || 5432,
|
port: Number(env.POSTGRES_PORT) || 5432,
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -123,9 +123,6 @@ export class CheckObjeniousRequests {
|
|||||||
|
|
||||||
if (uorStatus == "finished") {
|
if (uorStatus == "finished") {
|
||||||
console.log(" ****> Status", uorStatus)
|
console.log(" ****> Status", uorStatus)
|
||||||
if (uorStatus != "finished") {
|
|
||||||
console.error("!!! Notificando estado no finished")
|
|
||||||
}
|
|
||||||
const targetIccids = originalAction.iccids
|
const targetIccids = originalAction.iccids
|
||||||
const lineData = await this.getLineData(targetIccids)
|
const lineData = await this.getLineData(targetIccids)
|
||||||
console.log("[i] lineData", lineData.content[0])
|
console.log("[i] lineData", lineData.content[0])
|
||||||
@@ -219,7 +216,7 @@ export class CheckObjeniousRequests {
|
|||||||
const PATH = "/actions/requests/"
|
const PATH = "/actions/requests/"
|
||||||
const operationsList = structuredClone(requestList)
|
const operationsList = structuredClone(requestList)
|
||||||
|
|
||||||
|
// TODO: El for es gigantesco hay que simplificar partes
|
||||||
for (const request of operationsList) {
|
for (const request of operationsList) {
|
||||||
if (request.id == undefined) continue;
|
if (request.id == undefined) continue;
|
||||||
|
|
||||||
@@ -232,13 +229,50 @@ export class CheckObjeniousRequests {
|
|||||||
try {
|
try {
|
||||||
res = await req
|
res = await req
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error("Error comprobando el estado de ", request, e)
|
console.error("[x] Error comprobando el estado de ", request, e)
|
||||||
//todo actualizar el estado para incluir el error
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 2. Casos de error o id no generada
|
||||||
|
if (res.data.massActionIds.length == 0) {
|
||||||
|
// Si no hay es que *puede* que haya un problema o no se ha generado todavia
|
||||||
|
const reports = res.data.actionRequestReports
|
||||||
|
// Se entiende que no hay report ni id = está a la espera
|
||||||
|
if (reports.length == 0) continue;
|
||||||
|
|
||||||
|
// ! Hay minimo un report -> se considera error y se para
|
||||||
|
const updateData: ObjeniousOperationChange = {
|
||||||
|
operation_id: request.id,
|
||||||
|
new_status: "error",
|
||||||
|
error: JSON.stringify(reports[0].actionRequestReportDataDTOs)
|
||||||
|
}
|
||||||
|
|
||||||
|
const updateRes = await this.operationsRepository.updateOperation(updateData)
|
||||||
|
if (updateRes.error != undefined) {
|
||||||
|
console.error("[x] Error actualizando el estado de la operacion", updateData.error)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (request.correlation_id != undefined) {
|
||||||
|
this.orderRepository.errorOrder({
|
||||||
|
correlation_id: request.correlation_id,
|
||||||
|
status: "failed",
|
||||||
|
error: "MassId no obtenida",
|
||||||
|
reason: "MassId no obtenida",
|
||||||
|
stackTrace: JSON.stringify(reports[0].actionRequestReportDataDTOs)
|
||||||
|
}).then(e => {
|
||||||
|
if (e.error != undefined) {
|
||||||
|
console.error("[x] Error actualizando el estado del Order con correlation_id: ", request.correlation_id)
|
||||||
|
console.error(e.error)
|
||||||
|
}
|
||||||
|
}).catch(e => {
|
||||||
|
console.error("[x] Error actualizando el estado del Order con correlation_id: ", request.correlation_id)
|
||||||
|
})
|
||||||
|
}
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 2. Modificacion del massId si ha habido un cambio
|
|
||||||
const massActionId = res.data.massActionIds[0]
|
const massActionId = res.data.massActionIds[0]
|
||||||
|
// 3. Modificacion del massId si ha habido un cambio
|
||||||
try {
|
try {
|
||||||
if (res.status == 200 && res.data != undefined && massActionId != undefined) {
|
if (res.status == 200 && res.data != undefined && massActionId != undefined) {
|
||||||
const updateData: ObjeniousOperationChange = {
|
const updateData: ObjeniousOperationChange = {
|
||||||
@@ -252,7 +286,7 @@ export class CheckObjeniousRequests {
|
|||||||
request.mass_action_id = String(massActionId)
|
request.mass_action_id = String(massActionId)
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.log("Error actualizando el estado de ", request)
|
console.log("[x] Error actualizando el estado de ", request)
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -274,7 +308,17 @@ export class CheckObjeniousRequests {
|
|||||||
"x-apikey-sim-activation": env.SIM_ACTIVATION_API_KEY
|
"x-apikey-sim-activation": env.SIM_ACTIVATION_API_KEY
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
await req
|
try {
|
||||||
|
const res = await req
|
||||||
|
if (res.status != 200) {
|
||||||
|
console.error("[x] Error enviando el mail de confirmacion para ", operation, " status ", res.status, res.statusText)
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
console.error("[x] Error enviando el mail de confirmacion para ", operation)
|
||||||
|
console.error(e)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -62,11 +62,14 @@ export type CreateOrderDTO = Pick<
|
|||||||
'correlation_id' | 'exchange' | 'routing_key' | 'order_type' | 'payload' | 'webhook_host' | 'webhook_endpoint'
|
'correlation_id' | 'exchange' | 'routing_key' | 'order_type' | 'payload' | 'webhook_host' | 'webhook_endpoint'
|
||||||
>;
|
>;
|
||||||
|
|
||||||
export type UpdateOrderDTO =
|
type IdOrCorrelationID =
|
||||||
(
|
(
|
||||||
{ id: number, correlation_id?: never } |
|
{ id: number, correlation_id?: never } |
|
||||||
{ id?: never, correlation_id: string }
|
{ id?: never, correlation_id: string }
|
||||||
)
|
)
|
||||||
|
|
||||||
|
export type UpdateOrderDTO =
|
||||||
|
IdOrCorrelationID
|
||||||
&
|
&
|
||||||
{
|
{
|
||||||
new_status: OrderStatus,
|
new_status: OrderStatus,
|
||||||
@@ -74,12 +77,20 @@ export type UpdateOrderDTO =
|
|||||||
}
|
}
|
||||||
|
|
||||||
export type FinishOrderDTO =
|
export type FinishOrderDTO =
|
||||||
(
|
IdOrCorrelationID
|
||||||
{ id: number, correlation_id?: never } |
|
|
||||||
{ id?: never, correlation_id: string }
|
|
||||||
)
|
|
||||||
&
|
&
|
||||||
{
|
{
|
||||||
reason?: string
|
reason?: string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export type ErrorOrderDTO =
|
||||||
|
IdOrCorrelationID
|
||||||
|
&
|
||||||
|
{
|
||||||
|
status: "failed" | "dlx",
|
||||||
|
reason: string,
|
||||||
|
error?: string,
|
||||||
|
stackTrace?: string
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -46,10 +46,34 @@ export namespace Objenious {
|
|||||||
created: string,
|
created: string,
|
||||||
status: "NEW" | "RUNNING" | "OK" | "KO" | "REPLAYED" | "CANCELLED" | "CLOSED" | "DISABLED",
|
status: "NEW" | "RUNNING" | "OK" | "KO" | "REPLAYED" | "CANCELLED" | "CLOSED" | "DISABLED",
|
||||||
statusDate: string,
|
statusDate: string,
|
||||||
actionType: "PREACTIVATION_AND_ACTIVATION" | string, // todo: añadir el resto
|
actionType: ActionType
|
||||||
massActionIds: number[]
|
massActionIds: number[],
|
||||||
|
actionRequestReports:
|
||||||
|
{
|
||||||
|
requestId: string,
|
||||||
|
actionRequestReportDataDTOs: [
|
||||||
|
{
|
||||||
|
data: string,
|
||||||
|
newData: string | null,
|
||||||
|
iccid: string,
|
||||||
|
dataStatus: DataStatus
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}[],
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export type DataStatus = "DATA_INVALID_FORMAT" | "DATA_NOT_FOUND" | "DATA_NOT_ACTIVATED" | "SERVICE_DATA_NOT_ACTIVATED" |
|
||||||
|
"DATA_WRONG_STATUS" | "DATA_NOT_AUTHORIZED" | "DATA_CUSTOMER_ACCOUNT_NOT_AUTHORIZED" | "DATA_AMBIGUOUS" |
|
||||||
|
"NEW_DATA_INVALID_FORMAT" | "NEW_DATA_ALREADY_EXISTS" | "DUPLICATE_DATA" | "DATA_TERMINATION_VALIDATED" |
|
||||||
|
"DATA_TERMINATION_SECURISED" | "MAX_ALARM_INSTANCE" | "MAX_ALARM_INSTANCE_TO_CATCH_UP" |
|
||||||
|
"ACTIVATED_LINE_CANNOT_BE_TRANSFERED" | "ESIM_WRONG_STEP" | "ESIM_WRONG_PAIRED_VALUE" |
|
||||||
|
"ESIM_WRONG_DOWNLOAD_STATE" | "ESIM_WRONG_STATUS" | "ESIM_WRONG_FAMILY" | "ESIM_WRONG_CATEGORY" |
|
||||||
|
"ENTITY_STATUS_NOT_AUTHORIZED" | "LONG_LIFE_NOT_ALLOWED" | "RCARD_NOT_COMPATIBLE" | "APN_NOT_FOUND" |
|
||||||
|
"APN_OR_DNN_NOT_FOUND" | "APN_CONFIGURATION_NOT_FOUND" | "APN_CONFIGURATION_INVALID_PARAMETER_FILE" |
|
||||||
|
"IP_NOT_AVAILABLE" | "RADIUS_FIELD_LENGTH_NOT_ALLOWED" | "RADIUS_LOGIN_OR_PASSWORD_NOT_FOUND" | "RADIUS_PASSWORD_NOT_ALLOWED" |
|
||||||
|
"RADIUS_LOGIN_NOT_ALLOWED" | "NETWORK_NOT_ACTIVATED" | "CHANGE_CUSTOMER_ACCOUNT_NOT_AllOWED" | "CHANGE_OFFER_NOT_ALLOWED" |
|
||||||
|
"SIM_NOT_EUICC" | "OFFER_NOT_WSF_PALIER_FLOTTE_FR"
|
||||||
|
|
||||||
export type ActionType = "PREACTIVATION" | "PREACTIVATION_ACTIVATION" | "ACTIVATION" |
|
export type ActionType = "PREACTIVATION" | "PREACTIVATION_ACTIVATION" | "ACTIVATION" |
|
||||||
"STATUS_CHANGE" | "ICCID_CHANGE" | "EUICC_NOTIFICATION"
|
"STATUS_CHANGE" | "ICCID_CHANGE" | "EUICC_NOTIFICATION"
|
||||||
| "EUICC_AUDIT" | "MSISDN_CHANGE" | "ALARM_SETTING"
|
| "EUICC_AUDIT" | "MSISDN_CHANGE" | "ALARM_SETTING"
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
* TODO: Usar
|
* TODO: Usar
|
||||||
*/
|
*/
|
||||||
import { PoolClient, QueryResult, QueryResultRow } from "pg";
|
import { PoolClient, QueryResult, QueryResultRow } from "pg";
|
||||||
import { CreateOrderDTO, FinishOrderDTO, OrderTracking, UpdateOrderDTO } from "../domain/Order.js";
|
import { CreateOrderDTO, ErrorOrderDTO, FinishOrderDTO, OrderTracking, UpdateOrderDTO } from "../domain/Order.js";
|
||||||
import { Result } from "../domain/Result.js";
|
import { Result } from "../domain/Result.js";
|
||||||
import { PgClient } from "./PgClient.js";
|
import { PgClient } from "./PgClient.js";
|
||||||
import assert from "node:assert";
|
import assert from "node:assert";
|
||||||
@@ -353,22 +353,19 @@ export class OrderRepository {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// TODO: tema de poder filtrar por correlation_id
|
// TODO: tema de poder filtrar por correlation_id
|
||||||
public async errorOrder(args: {
|
public async errorOrder(args: ErrorOrderDTO): Promise<Result<string, OrderTracking<any>>> {
|
||||||
id: number,
|
|
||||||
status: "failed" | "dlx",
|
|
||||||
reason: string,
|
|
||||||
error?: string,
|
|
||||||
stackTrace?: string
|
|
||||||
}) {
|
|
||||||
const client = await this.pgClient.connect();
|
const client = await this.pgClient.connect();
|
||||||
await client.query('BEGIN');
|
await client.query('BEGIN');
|
||||||
|
|
||||||
|
const idType = ('id' in args) ? "id" : "correlation_id"
|
||||||
|
const idValue = (args.id != undefined) ? args.id : args.correlation_id
|
||||||
|
|
||||||
// 1. Se consulta la order de base
|
// 1. Se consulta la order de base
|
||||||
const qCurrentOrder = `
|
const qCurrentOrder = `
|
||||||
SELECT * FROM order_tracking
|
SELECT * FROM order_tracking
|
||||||
WHERE id = $1
|
WHERE ${idType} = $1
|
||||||
`
|
`
|
||||||
const vCurrentOrder = [args.id]
|
const vCurrentOrder = [idValue]
|
||||||
|
|
||||||
const currentOrderResult = await this.getFirst(client.query<OrderTracking<any>>(qCurrentOrder, vCurrentOrder))
|
const currentOrderResult = await this.getFirst(client.query<OrderTracking<any>>(qCurrentOrder, vCurrentOrder))
|
||||||
|
|
||||||
@@ -378,6 +375,7 @@ export class OrderRepository {
|
|||||||
return currentOrderResult
|
return currentOrderResult
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const id = currentOrderResult.data.id // Saco el id para evitar busacr por correlation_id que es mas lento
|
||||||
const currentOrder = currentOrderResult.data!
|
const currentOrder = currentOrderResult.data!
|
||||||
|
|
||||||
// 3. Si todo ok se actualiza el order
|
// 3. Si todo ok se actualiza el order
|
||||||
@@ -395,7 +393,7 @@ export class OrderRepository {
|
|||||||
WHERE id = $1
|
WHERE id = $1
|
||||||
RETURNING id, status, update_date;
|
RETURNING id, status, update_date;
|
||||||
`
|
`
|
||||||
const vOrderTracking = [args.id, args.status, args.error, args.stackTrace]
|
const vOrderTracking = [id, args.status, args.error, args.stackTrace]
|
||||||
const updatedOrderResult = await this.getFirst(
|
const updatedOrderResult = await this.getFirst(
|
||||||
client.query<{ id: number, status: string, update_date: string }>(uOrderTracking, vOrderTracking)
|
client.query<{ id: number, status: string, update_date: string }>(uOrderTracking, vOrderTracking)
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user