Registro de peticiones y cron
Tambien mejora de las rutas de typescript
This commit is contained in:
@@ -1,14 +1,18 @@
|
||||
// PEM ?
|
||||
|
||||
import { env } from "#config/env";
|
||||
/**
|
||||
* TODO:
|
||||
* Está demasiado acoplado a objenious, hay que sacar un servicio jwt general para
|
||||
* el cliente HTTP
|
||||
*/
|
||||
|
||||
import { env } from "#config/env/index.js";
|
||||
import fs from "fs"
|
||||
|
||||
import {
|
||||
JWTToken
|
||||
} from "#shared/domain/JWT"
|
||||
} from "#shared/domain/JWT.js"
|
||||
import axios, { AxiosError } from "axios";
|
||||
import { sign } from "node:crypto"
|
||||
import { ClientRequest } from "node:http";
|
||||
|
||||
type GrantAccessRequestBody = {
|
||||
grant_type: string,
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import { ActionData, ActivationData } from "#domain/DTOs/objeniousapi.js"
|
||||
import { HttpClient } from "#shared/infrastructure/HTTPClient.js"
|
||||
import { AxiosError } from "axios"
|
||||
import { Result } from "#shared/domain/Result"
|
||||
import { ObjeniousOperation, IOperationsRepository as OperationsRepositoryPort } from "#domain/operationsRepository.port"
|
||||
import { Result } from "sim-shared/domain/Result.js"
|
||||
import { ObjeniousOperation, IOperationsRepository as OperationsRepositoryPort } from "#domain/operationsRepository.port.js"
|
||||
|
||||
// TODO:
|
||||
// - Pasar a un archivo de DTOs
|
||||
@@ -38,12 +38,13 @@ export class SimUseCases {
|
||||
console.log("[!] El status de la respuesta es", response.status)
|
||||
|
||||
if (response.status == 200) {
|
||||
console.log("Activacion con exito", response.data.response)
|
||||
console.log("Activacion con exito", response.data)
|
||||
|
||||
const operation: ObjeniousOperation = {
|
||||
operation: "activate",
|
||||
iccids: activationData.identifier.identifiers,
|
||||
status: "noMassID"
|
||||
status: "noMassID",
|
||||
request_id: response.data.requestId
|
||||
}
|
||||
|
||||
this.logOperation(operation).then(e => {
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import { loadEnvFile } from "node:process";
|
||||
import path from "node:path";
|
||||
|
||||
loadEnvFile(path.join(__dirname, "../../../../.env")) // Global
|
||||
loadEnvFile(path.join(__dirname, "../../.env")) // base
|
||||
loadEnvFile(path.join("../../.env")) // Global
|
||||
loadEnvFile(path.join("./.env")) // base
|
||||
|
||||
export const env = {
|
||||
ENVIRONMENT: process.env.ENVIORMENT,
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { Result } from "#shared/domain/Result";
|
||||
import { Result } from "#shared/domain/Result.js";
|
||||
|
||||
export type StatusEnum = 'noRequestID' | 'noMassID' | 'running' | 'finished' | 'error' | 'other';
|
||||
export type StatusEnum = Objenious.Status | 'noMassID';
|
||||
|
||||
export interface IOperationsRepository {
|
||||
createOperation(data: ObjeniousOperation): Promise<Result<string, ObjeniousOperation>>
|
||||
@@ -20,15 +20,73 @@ export type ObjeniousOperation = {
|
||||
end_date?: Date | null;
|
||||
error?: string | null;
|
||||
status: StatusEnum;
|
||||
last_change_date?: string;
|
||||
}
|
||||
|
||||
export type ObjeniousOperationChange = {
|
||||
id?: number;
|
||||
operation_id: number;
|
||||
creation_date: Date;
|
||||
info?: string | null;
|
||||
error?: string | null;
|
||||
new_status: StatusEnum;
|
||||
new_request_id?: string;
|
||||
new_mass_action_id?: string;
|
||||
}
|
||||
|
||||
export namespace Objenious {
|
||||
export type Status = "STAND_BY" | "IN_PROGRESS" | "ENDED" | "CANCELLED";
|
||||
export type Identifier = "IMSI" | "MSISDN" | "REFERENCE" | "ICCID" | "IMEI"
|
||||
export type ResponseGetRequestById = {
|
||||
created: string,
|
||||
status: "NEW" | "RUNNING" | "OK" | "KO" | "REPLAYED" | "CANCELLED" | "CLOSED" | "DISABLED",
|
||||
statusDate: string,
|
||||
actionType: "PREACTIVATION_AND_ACTIVATION" | string, // todo: añadir el resto
|
||||
massActionIds: number[]
|
||||
}
|
||||
|
||||
export type ActionType = "PREACTIVATION" | "PREACTIVATION_ACTIVATION" | "ACTIVATION" |
|
||||
"STATUS_CHANGE" | "ICCID_CHANGE" | "EUICC_NOTIFICATION"
|
||||
| "EUICC_AUDIT" | "MSISDN_CHANGE" | "ALARM_SETTING"
|
||||
| "ALARM_UNSETTING" | "CUSTOM_FIELDS_UPDATE" | "SERVICE_CHANGE"
|
||||
| "SEND_SMS" | "CHANGE_OFFER" | "PORT_IN"
|
||||
| "PORT_OUT" | "CHANGE_CUSTOMER_ACCOUNT" | "SIMCARD_TRANSFER"
|
||||
| "GEO_LOCATION" | "UPDATE_COMMITMENT" | "COACH_M2M"
|
||||
| "PP_RECHARGE" | "TERMINATION_DFE" | "DO_ORDER_PAYMENT"
|
||||
| "DO_TOP_UP" | "RADIUS_READ" | "RADIUS_UPDATE"
|
||||
| "RADIUS_SYNCHRONIZE" | "NETWORK_RESET" | "UPDATE_YORK_COMMUNITY"
|
||||
| "SUSPENSION" | "REACTIVATION" | "RESILIATION"
|
||||
| "SORTIE_TEST" | "VALIDATION_RESILIATION" | "REFUS_RESILIATION";
|
||||
|
||||
export type ParametersGetMassAction = {
|
||||
massActionId?: string,
|
||||
unitActionId?: string,
|
||||
createDateMin?: string,
|
||||
createDateMax?: string,
|
||||
dueDateMin?: string,
|
||||
dueDateMax?: string,
|
||||
endDateMin?: string,
|
||||
endDateMax?: string,
|
||||
"identifier.identifiers"?: string[],
|
||||
"identifier.identifierType"?: Identifier,
|
||||
actionTypes?: ActionType,
|
||||
errorCodes?: string[],
|
||||
pageNumber?: number,
|
||||
pageSize?: number
|
||||
}
|
||||
|
||||
export type ResponseGetMassAction = {
|
||||
id: number,
|
||||
loginCreator?: string,
|
||||
longinCancellor?: string,
|
||||
actionType: ActionType,
|
||||
dueDate?: string,
|
||||
targetActionNumber?: number,
|
||||
created: string,
|
||||
started?: string,
|
||||
ended?: string,
|
||||
status: Status,
|
||||
info?: string
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -1,15 +1,16 @@
|
||||
|
||||
import { OperationsRepository } from "#adapters/OperationRepository.js"
|
||||
import { startRMQClient } from "#config/eventBus.config"
|
||||
import { httpInstance } from "#config/httpClient.config"
|
||||
import { startRMQClient } from "#config/eventBus.config.js"
|
||||
import { httpInstance } from "#config/httpClient.config.js"
|
||||
import { pgPool } from "#config/postgreConfig.js"
|
||||
import { PgClient } from "#shared/infrastructure/PgClient.js"
|
||||
import { SimUseCases } from "aplication/Sim.usecases.js"
|
||||
import { SimController } from "./aplication/Sim.controller.js"
|
||||
import { SimRouter } from "./aplication/Sim.router.js"
|
||||
import { SimUseCases } from "./aplication/Sim.usecases.js"
|
||||
|
||||
async function startWorker() {
|
||||
const rmqClient = await startRMQClient()
|
||||
|
||||
const httpClient = httpInstance
|
||||
|
||||
const pgClient = new PgClient({ pool: pgPool })
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { IOperationsRepository, ObjeniousOperation, ObjeniousOperationChange } from "#domain/operationsRepository.port";
|
||||
import { Result } from "#shared/domain/Result";
|
||||
import { PgClient } from "#shared/infrastructure/PgClient";
|
||||
import { IOperationsRepository, ObjeniousOperation, ObjeniousOperationChange } from "#domain/operationsRepository.port.js";
|
||||
import { Result } from "sim-shared/domain/Result.js";
|
||||
import { PgClient } from "sim-shared/infrastructure/PgClient.js";
|
||||
|
||||
|
||||
|
||||
@@ -33,8 +33,13 @@ export class OperationsRepository implements IOperationsRepository {
|
||||
// 1. Actualizar objenious_operation
|
||||
const updateOpQuery = `
|
||||
UPDATE objenious_operation
|
||||
SET status = $1, error = $2, request_id = $3, mass_action_id = $4, last_change_date = now(),
|
||||
end_date = CASE WHEN $1 IN ('finished', 'error') THEN now() ELSE end_date END
|
||||
SET
|
||||
status = $1,
|
||||
error = COALESCE($2,error),
|
||||
request_id = COALESCE($3, request_id),
|
||||
mass_action_id = COALESCE($4, mass_action_id),
|
||||
last_change_date = now(),
|
||||
end_date = CASE WHEN $1 IN ('finished', 'error') THEN now() ELSE end_date END
|
||||
WHERE id = $5`;
|
||||
const operation = await client.query<ObjeniousOperation>(updateOpQuery, [new_status, error, new_request_id, new_mass_action_id, id]);
|
||||
|
||||
|
||||
@@ -1,13 +1,15 @@
|
||||
{
|
||||
"name": "sim-consumidor-objenious",
|
||||
"version": "1.0.0",
|
||||
"type": "module",
|
||||
"description": "consumidor generico de envetos de RMQ",
|
||||
"main": "index.ts",
|
||||
"scripts": {
|
||||
"test": "echo \"Error: no test specified\" && exit 1",
|
||||
"dev": "tsx watch index.ts",
|
||||
"build": "yarn tsc --project tsconfig.json && yarn tsc-alias && cp .env ../../dist/packages/sim-consumidor-objenious/",
|
||||
"start": "node ../../dist/packages/sim-consumidor-objenious/index.js"
|
||||
"start": "node ../../dist/packages/sim-consumidor-objenious/index.js",
|
||||
"type:test": "tsc --noEmit"
|
||||
},
|
||||
"author": "",
|
||||
"license": "ISC",
|
||||
@@ -18,6 +20,7 @@
|
||||
"cors": "*",
|
||||
"dotenv": "*",
|
||||
"express": "*",
|
||||
"sim-shared": "sim-shared:*",
|
||||
"typescript": "*"
|
||||
},
|
||||
"devDependencies": {
|
||||
|
||||
Reference in New Issue
Block a user