Compare commits
4 Commits
1.3.1
...
alarmas-ob
| Author | SHA1 | Date | |
|---|---|---|---|
| 7c2e86779a | |||
| 1780cf1743 | |||
| 10104c202f | |||
| ef8222ae30 |
1
packages/sim-alarmas-objenious/.env
Normal file
1
packages/sim-alarmas-objenious/.env
Normal file
@@ -0,0 +1 @@
|
||||
PORT=3001
|
||||
@@ -0,0 +1,18 @@
|
||||
import { Request, Response } from "express"
|
||||
|
||||
export class AlarmsController {
|
||||
constructor() {
|
||||
// Alarm usecases
|
||||
}
|
||||
|
||||
public recibe() {
|
||||
return (req: Request, res: Response) => {
|
||||
const body = req.body()
|
||||
const header = req.headers
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
14
packages/sim-alarmas-objenious/aplication/Alarms.usecases.ts
Normal file
14
packages/sim-alarmas-objenious/aplication/Alarms.usecases.ts
Normal file
@@ -0,0 +1,14 @@
|
||||
import { PgClient } from "sim-shared/infrastructure/PgClient.js";
|
||||
|
||||
export class AlarmUsecases {
|
||||
constructor(
|
||||
private alarmRepository: any
|
||||
) {
|
||||
|
||||
}
|
||||
|
||||
|
||||
public saveAlarm() {
|
||||
|
||||
}
|
||||
}
|
||||
23
packages/sim-alarmas-objenious/config/env/index.ts
vendored
Normal file
23
packages/sim-alarmas-objenious/config/env/index.ts
vendored
Normal file
@@ -0,0 +1,23 @@
|
||||
import { loadEnvFile } from "node:process";
|
||||
loadEnvFile("../../.env")
|
||||
|
||||
export const env = {
|
||||
PORT: Number(process.env.PORT),
|
||||
ENVIRONMENT: process.env.ENVIORMENT,
|
||||
POSTGRES_USER: process.env.POSTGRES_USER,
|
||||
POSTGRES_PASSWORD: process.env.POSTGRES_PASSWORD,
|
||||
POSTGRES_PORT: process.env.POSTGRES_PORT,
|
||||
POSTGRES_HOST: process.env.POSTGRES_HOST,
|
||||
POSTGRES_DATABASE: process.env.POSTGRES_DATABASE,
|
||||
RABBITMQ_HOST: String(process.env.RABBITMQ_HOST ?? "localhost"),
|
||||
RABBITMQ_USER: String(process.env.RABBITMQ_USER ?? "test"),
|
||||
RABBITMQ_PASSWORD: String(process.env.RABBITMQ_PASSWORD ?? "test"),
|
||||
RABBITMQ_EXCHANGE: String(process.env.RABBITMQ_EXCHANGE ?? "/"),
|
||||
RABBITMQ_PORT: parseInt(process.env.RABBITMQ_PORT ?? "5672"),
|
||||
RABBITMQ_MODULENAME: process.env.MODULENAME,
|
||||
RABBITMQ_TTL: process.env.RABBITMQ_TTL,
|
||||
RABBITMQ_SECURE: process.env.RABBITMQ_SECURE,
|
||||
RABBITMQ_RETRY_INTERVAL: process.env.RABBITMQ_INTERVAL,
|
||||
RABBITMQ_VHOST: String(process.env.RABBITMQ_VHOST),
|
||||
};
|
||||
|
||||
18
packages/sim-alarmas-objenious/config/postgreConfig.ts
Normal file
18
packages/sim-alarmas-objenious/config/postgreConfig.ts
Normal file
@@ -0,0 +1,18 @@
|
||||
import { Pool } from 'pg';
|
||||
import { PgClient } from 'sim-shared/infrastructure/PgClient.js'
|
||||
import { env } from './env/index.js';
|
||||
|
||||
// Configuracion de la conexion a la BDD, deberia ser la
|
||||
// Misma para todos los servicios pero hasta que se unifique todo
|
||||
// se hace una por servicio.
|
||||
export const pgPool = new Pool({
|
||||
user: env.POSTGRES_USER,
|
||||
host: env.POSTGRES_HOST,
|
||||
database: env.POSTGRES_DATABASE,
|
||||
password: env.POSTGRES_PASSWORD,
|
||||
port: Number(env.POSTGRES_PORT) || 5432,
|
||||
});
|
||||
|
||||
export const postgresClient = new PgClient({
|
||||
pool: pgPool
|
||||
})
|
||||
62
packages/sim-alarmas-objenious/domain/alarmTypes.ts
Normal file
62
packages/sim-alarmas-objenious/domain/alarmTypes.ts
Normal file
@@ -0,0 +1,62 @@
|
||||
export type ObjeniousAlarmType =
|
||||
"PLMN_CHANGE" |
|
||||
"COUNTRY_CHANGE" |
|
||||
"OVER_CONSUMPTION_VOLUME" |
|
||||
"UNDER_CONSUMPTION_VOLUME" |
|
||||
"IMEI_CHANGE" |
|
||||
"OVER_CONSUMPTION_VOLUME" |
|
||||
string
|
||||
|
||||
export type ObjeniousAlarm = {
|
||||
alarmId: Number,
|
||||
emissionDate: Date //"07/02/2019 14:44:00"
|
||||
alarmType: ObjeniousAlarmType,
|
||||
lineInfos: {
|
||||
msisdn: string,
|
||||
iccid: string
|
||||
},
|
||||
change?: ObjeniousChangeTypes,
|
||||
usage?: ObjeniousUsageTypes
|
||||
}
|
||||
|
||||
export type ObjeniousChangeTypes = ChangePayload | ImeiChangePayload;
|
||||
export type ObjeniousUsageTypes = UsageAlarmPayload | OverConsumptionPayload;
|
||||
|
||||
/**
|
||||
* PLMN_CHANGE
|
||||
* COUNTRY_CHANGE
|
||||
* STATUS_CHANGE
|
||||
* */
|
||||
export type ChangePayload = {
|
||||
previous: string,
|
||||
current: string
|
||||
}
|
||||
|
||||
/**
|
||||
* IMEI_CHANGE
|
||||
*/
|
||||
export type ImeiChangePayload = {
|
||||
previous: string,//"42947662490276",
|
||||
current: string, //"74845559130697",
|
||||
previousManufacturer: string, //"u-blox AG",
|
||||
currentManufacturer: string, //"SierraWireless"
|
||||
}
|
||||
|
||||
/**
|
||||
* OVER_CONSUMPTION_VOLUME
|
||||
* UNDER_CONSUMPTION_VOLUME
|
||||
*/
|
||||
export type UsageAlarmPayload = {
|
||||
type: string,
|
||||
threshold: string,
|
||||
trigerValue: string
|
||||
}
|
||||
|
||||
/**
|
||||
* OVER_CONSUMPTION_VOLUME
|
||||
*/
|
||||
export type OverConsumptionPayload = {
|
||||
type: string, //"data-sms-smsIN-voiceOUT",
|
||||
threshold: string, // "500-200-100-10",
|
||||
triggerValue: string, // "600-300-101-15"
|
||||
}
|
||||
29
packages/sim-alarmas-objenious/index.ts
Normal file
29
packages/sim-alarmas-objenious/index.ts
Normal file
@@ -0,0 +1,29 @@
|
||||
import express from "express"
|
||||
import cors from 'cors';
|
||||
import { env } from "#config/env/index.js"
|
||||
import { AlarmsController } from "aplication/Alarms.controller";
|
||||
|
||||
const PORT = env.PORT
|
||||
const HOSTNAME = "0.0.0.0"
|
||||
const app = express()
|
||||
|
||||
// Instancias
|
||||
const alarmsController = new AlarmsController();
|
||||
|
||||
// Middleware
|
||||
app.use(cors());
|
||||
|
||||
app.use(express.json());
|
||||
app.use(express.urlencoded({ extended: true }));
|
||||
|
||||
app.use("/fr/alarms", alarmsController.recibe())
|
||||
|
||||
app.get("/health", (req, res) => {
|
||||
res.status(200).json({ status: "ok" })
|
||||
})
|
||||
|
||||
app.listen(PORT, HOSTNAME, () => {
|
||||
console.log("[o] Servidor iniciado en el puerto %d", PORT)
|
||||
})
|
||||
|
||||
export default {}
|
||||
@@ -0,0 +1,10 @@
|
||||
import { PgClient } from "sim-shared/infrastructure/PgClient.js";
|
||||
|
||||
export class AlarmsRepository {
|
||||
constructor(private pgClient: PgClient) {
|
||||
}
|
||||
|
||||
public createAlarm() {
|
||||
|
||||
}
|
||||
}
|
||||
76
packages/sim-alarmas-objenious/package.json
Normal file
76
packages/sim-alarmas-objenious/package.json
Normal file
@@ -0,0 +1,76 @@
|
||||
{
|
||||
"name": "sim-alarmas-objenious",
|
||||
"version": "1.0.0",
|
||||
"description": "Recibe las alarmas de los webhook de objenious",
|
||||
"main": "index.ts",
|
||||
"scripts": {
|
||||
"test": "node --import tsx --test ./**/*.test.ts",
|
||||
"build": "tsc --build && tsc-alias -p tsconfig.json && cp package.json ../../dist/packages/sim-alarmas-objenious/",
|
||||
"dev": "tsx watch index.ts",
|
||||
"start": "node ../../dist/packages/sim-alarmas-objenious/index.js"
|
||||
},
|
||||
"author": "",
|
||||
"license": "ISC",
|
||||
"packageManager": "yarn@4.12.0",
|
||||
"imports": {
|
||||
"#config/*.js": {
|
||||
"types": "./config/*.ts",
|
||||
"default": "./config/*.js"
|
||||
},
|
||||
"#config/*": {
|
||||
"types": "./config/*.ts",
|
||||
"default": "./config/*.js"
|
||||
},
|
||||
"#adapters/*.js": {
|
||||
"types": "./adapters/*.ts",
|
||||
"default": "./adapters/*.js"
|
||||
},
|
||||
"#adapters/*": {
|
||||
"types": "./adapters/*.ts",
|
||||
"default": "./adapters/*.js"
|
||||
},
|
||||
"#domain/*.js": {
|
||||
"types": "./domain/*.ts",
|
||||
"default": "./domain/*.js"
|
||||
},
|
||||
"#domain/*": {
|
||||
"types": "./domain/*.ts",
|
||||
"default": "./domain/*.js"
|
||||
},
|
||||
"#ports/*.js": {
|
||||
"types": "./ports/*.ts",
|
||||
"default": "./ports/*.js"
|
||||
},
|
||||
"#ports/*": {
|
||||
"types": "./ports/*.ts",
|
||||
"default": "./ports/*.js"
|
||||
},
|
||||
"#tests/*.js": {
|
||||
"types": "./__tests__/*.ts",
|
||||
"default": "./__tests__/*.js"
|
||||
},
|
||||
"#tests/*": {
|
||||
"types": "./__tests__/*.ts",
|
||||
"default": "./__tests__/*.js"
|
||||
}
|
||||
},
|
||||
"dependencies": {
|
||||
"@tsconfig/node22": "*",
|
||||
"amqplib": "^0.10.9",
|
||||
"cors": "*",
|
||||
"dotenv": "*",
|
||||
"express": "*",
|
||||
"typescript": "*"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/amqplib": "^0.10.8",
|
||||
"@types/cors": "*",
|
||||
"@types/express": "*",
|
||||
"@types/node": "*",
|
||||
"@types/supertest": "*",
|
||||
"prettier": "*",
|
||||
"supertest": "*",
|
||||
"tsx": "*",
|
||||
"vitest": "*"
|
||||
}
|
||||
}
|
||||
17
packages/sim-alarmas-objenious/tsconfig.json
Normal file
17
packages/sim-alarmas-objenious/tsconfig.json
Normal file
@@ -0,0 +1,17 @@
|
||||
{
|
||||
"extends": "../../tsconfig.json",
|
||||
"compilerOptions": {
|
||||
"outDir": "../../dist",
|
||||
"baseUrl": ".",
|
||||
},
|
||||
"exclude": [
|
||||
"node_modules"
|
||||
],
|
||||
"include": [
|
||||
"**/*.ts",
|
||||
"src/**/*.d.ts"
|
||||
],
|
||||
"files": [
|
||||
"index.ts"
|
||||
]
|
||||
}
|
||||
Reference in New Issue
Block a user