Compare commits
15 Commits
seguimient
...
1.1.1
| Author | SHA1 | Date | |
|---|---|---|---|
| 39c0e87758 | |||
| 5771972e2a | |||
| ea13403dc3 | |||
| 8d9a9b84b8 | |||
| 9b92f3506b | |||
| 1798118f6b | |||
| eba2b8c569 | |||
| b6b2cf6cc8 | |||
| a0faa2d105 | |||
| d323f804fc | |||
| 978454754c | |||
| b6091b15da | |||
| a6794a061b | |||
| fafea3ce04 | |||
| 992f639f35 |
8
.env
8
.env
@@ -5,8 +5,8 @@ RABBITMQ_PASSWORD=guest
|
||||
|
||||
ENVIORMENT=development
|
||||
|
||||
RABBITMQ_HOST=rabbitmq-sim-broker
|
||||
# RABBITMQ_HOST=localhost
|
||||
#RABBITMQ_HOST=rabbitmq-sim-broker
|
||||
RABBITMQ_HOST=localhost
|
||||
RABBITMQ_PORT=5672
|
||||
RABBITMQ_USER=guest
|
||||
RABBITMQ_PASSWORD=guest
|
||||
@@ -14,8 +14,8 @@ RABBITMQ_SECURE=false
|
||||
RABBITMQ_VHOST=sim-vhost
|
||||
|
||||
# Hay cosas que unificar de varios servicios
|
||||
POSTGRES_HOST=postgresql-sim
|
||||
# POSTGRES_HOST=localhost
|
||||
#POSTGRES_HOST=postgresql-sim
|
||||
POSTGRES_HOST=localhost
|
||||
POSTGRES_DB=postgres
|
||||
POSTGRES_DATABASE=postgres
|
||||
POSTGRES_PORT=5433
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
# stage base para coordinar las fases de build y ejecucion
|
||||
FROM node:22-alpine AS base
|
||||
WORKDIR /usr/local/app
|
||||
COPY ./package.json ./yarn.lock ./
|
||||
COPY ./package.json ./
|
||||
#COPY ./package.json ./yarn.lock ./
|
||||
RUN corepack enable && \
|
||||
corepack prepare yarn@4.12.0 --activate
|
||||
# copia el codigo en general
|
||||
|
||||
@@ -12,7 +12,7 @@ COPY ./package.json ./
|
||||
# Force node-modules linker (no .yarnrc.yml in build context)
|
||||
RUN echo 'nodeLinker: node-modules' > .yarnrc.yml
|
||||
|
||||
RUN yarn install
|
||||
RUN yarn install
|
||||
|
||||
RUN mkdir -p dist && ln -sf ../packages dist/packages
|
||||
|
||||
|
||||
@@ -17,7 +17,7 @@ pipeline {
|
||||
sh 'npm install -g yarn'
|
||||
sh 'corepack enable'
|
||||
sh 'corepack prepare yarn@4.12.0 --activate'
|
||||
sh 'yarn install --immutable'
|
||||
sh 'yarn install'
|
||||
}
|
||||
}
|
||||
stage("🧱 Building") {
|
||||
|
||||
@@ -11,7 +11,7 @@ post {
|
||||
}
|
||||
|
||||
body:form-urlencoded {
|
||||
iccid: 8933201125065160331
|
||||
iccid: 8933201125068886692
|
||||
offer: SAVEFAMILY1
|
||||
}
|
||||
|
||||
|
||||
@@ -18,3 +18,38 @@ settings {
|
||||
encodeUrl: true
|
||||
timeout: 0
|
||||
}
|
||||
|
||||
docs {
|
||||
El endpoint recibe como body
|
||||
```
|
||||
{
|
||||
iccid: string,
|
||||
update_webhook?: string
|
||||
}
|
||||
```
|
||||
|
||||
`update_webhook` está en desarrollo, pero será donde se mande la actualizacion de la cancelación cuando haya una respuesta de la API externa.
|
||||
|
||||
Si la llamada tiene exito devuelve:
|
||||
``` json
|
||||
{
|
||||
data: {
|
||||
iccid: string,
|
||||
message_id: string,
|
||||
operation: "cancelation"
|
||||
}
|
||||
}
|
||||
|
||||
```
|
||||
message_id se usará para la llamada /orders/message_id/}{message_id}
|
||||
|
||||
Si la llamada falla devolvera:
|
||||
```json
|
||||
{
|
||||
errors: {
|
||||
msg: string
|
||||
... (campos extra de gestion del error)
|
||||
}
|
||||
}
|
||||
```
|
||||
}
|
||||
|
||||
34
docs/sim-api/collection.bru
Normal file
34
docs/sim-api/collection.bru
Normal file
@@ -0,0 +1,34 @@
|
||||
docs {
|
||||
Los endpoint tienen unos campos comunes de entrada:
|
||||
```ts
|
||||
{
|
||||
iccid: string,
|
||||
update_webhook?: string
|
||||
}
|
||||
```
|
||||
|
||||
`update_webhook` está en desarrollo, pero será donde se mande la actualizacion de la cancelación cuando haya una respuesta de la API externa.
|
||||
|
||||
Si la llamada tiene exito devuelve:
|
||||
```ts
|
||||
{
|
||||
data: {
|
||||
iccid: string,
|
||||
message_id: string,
|
||||
operation: string,
|
||||
}
|
||||
}
|
||||
|
||||
```
|
||||
message_id se usará para la llamada /orders/message_id/}{message_id}
|
||||
|
||||
Si la llamada falla devolvera:
|
||||
```ts
|
||||
{
|
||||
errors: {
|
||||
msg: string
|
||||
... (campos extra de gestion del error)
|
||||
}
|
||||
}
|
||||
```
|
||||
}
|
||||
1843
package-lock.json
generated
1843
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@@ -24,7 +24,7 @@
|
||||
"amqplib": "^0.10.9",
|
||||
"axios": "^1.13.3",
|
||||
"cors": "^2.8.5",
|
||||
"db-migrate": "https://git.savefamilygps.net/alvarsanmartin/herramienta-migracion.git",
|
||||
"db-migrate": "http://gitea:3000/alvarsanmartin/herramienta-migracion.git",
|
||||
"dotenv": "^17.2.3",
|
||||
"express": "^5.2.1",
|
||||
"pg": "^8.18.0",
|
||||
|
||||
@@ -3,20 +3,3 @@ RABBITMQ_USER=guest
|
||||
RABBITMQ_PASSWORD=guest
|
||||
|
||||
ENVIORMENT=development
|
||||
|
||||
RABBITMQ_HOST=rabbitmq-sim-broker
|
||||
#RABBITMQ_HOST=localhost
|
||||
RABBITMQ_PORT=5672
|
||||
RABBITMQ_USER=guest
|
||||
RABBITMQ_PASSWORD=guest
|
||||
RABBITMQ_SECURE=false
|
||||
RABBITMQ_VHOST=sim-vhost
|
||||
|
||||
# Hay cosas que unificar de varios servicios
|
||||
POSTGRES_DB=postgres
|
||||
POSTGRES_DATABASE=postres
|
||||
POSTGRES_HOST=postgresql-sim-1
|
||||
POSTGRES_PORT=5432
|
||||
DEV_POSTGRES_PORT=5432
|
||||
POSTGRES_USER=postgres
|
||||
POSTGRES_PASSWORD=1234
|
||||
|
||||
@@ -3,6 +3,7 @@ import { SimUsecases } from "./Sim.usecases.js"
|
||||
import { activationValidator, iccidValidator } from "./httpValidators.js"
|
||||
import { companyFromIccid } from "#domain/companies.js"
|
||||
import { BodyValidator } from "sim-shared/aplication/BodyValidator.js"
|
||||
import { tryCatch } from "packages/sim-shared/domain/Result.js"
|
||||
|
||||
|
||||
export class SimController {
|
||||
@@ -37,19 +38,21 @@ export class SimController {
|
||||
const body = req.body
|
||||
|
||||
// 1. Validacion del body
|
||||
try {
|
||||
if (args.validator != undefined)
|
||||
args.validator.validate(body)
|
||||
} catch (e) {
|
||||
if (args.onError != undefined) args.onError(body, e as string)
|
||||
res.status(422).json({
|
||||
errors: {
|
||||
msg: e
|
||||
}
|
||||
})
|
||||
if (args.validator != undefined) {
|
||||
const validationResult = args.validator.validate(body)
|
||||
if (validationResult.error != undefined) {
|
||||
res.status(422).json({
|
||||
errors: {
|
||||
...validationResult.error
|
||||
}
|
||||
})
|
||||
args.onError(body, validationResult.error.msg)
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
// 2. Transformacion del body
|
||||
// TODO: sustituir el try cach
|
||||
let data: P = body;
|
||||
try {
|
||||
if (args.mapBody != undefined)
|
||||
@@ -60,26 +63,33 @@ export class SimController {
|
||||
msg: "Error parseando el body: " + e
|
||||
}
|
||||
})
|
||||
args.onError(body, String(e))
|
||||
return 1;
|
||||
}
|
||||
|
||||
// 3. Aplicacion del UseCase
|
||||
try {
|
||||
const usecaseResult = await args.useCase(data)
|
||||
// 4. Se devuelve al usuario el caso de exito
|
||||
res.status(200).json(
|
||||
usecaseResult
|
||||
).send()
|
||||
args.onSuccess(data)
|
||||
} catch (err) {
|
||||
// TODO: todos los use cases tienen que pasar a devolver un Result<>
|
||||
const usecaseResult = await args.useCase(data) // no deberia hacer falta el trycatch
|
||||
|
||||
// 4. Casos de error del usecase
|
||||
if (usecaseResult.error != undefined) {
|
||||
// 4.1 Error del caso de uso
|
||||
res.status(500).json({
|
||||
errors: {
|
||||
msg: "Error general:" + err
|
||||
...usecaseResult.error
|
||||
}
|
||||
}).send()
|
||||
return;
|
||||
args.onError(body, usecaseResult.error.msg.message)
|
||||
return 1;
|
||||
}
|
||||
|
||||
// 5. Se devuelve al usuario el caso de exito
|
||||
res.status(200).json(
|
||||
usecaseResult.data
|
||||
).send()
|
||||
args.onSuccess(usecaseResult.data)
|
||||
return 0;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -92,155 +102,64 @@ export class SimController {
|
||||
console.log("OK", data)
|
||||
}
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
public preactivation() {
|
||||
return async (req: Request, res: Response) => {
|
||||
console.warn("[!] Se deberia de usar la peticion /sim/activate directamente")
|
||||
try {
|
||||
iccidValidator.validate(req.body)
|
||||
} catch (e) {
|
||||
res.status(422).json({
|
||||
errors: {
|
||||
msg: e
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
const { iccid } = req.body
|
||||
const compañia = companyFromIccid(iccid)
|
||||
|
||||
try {
|
||||
await this.simUseCases.preActivation({ iccid, compañia })
|
||||
|
||||
res.status(200).json({
|
||||
iccid: iccid,
|
||||
operation: "activation"
|
||||
}).send()
|
||||
} catch (err) {
|
||||
console.error("Error activando la sim ", req.body)
|
||||
res.status(500).json({
|
||||
errors: {
|
||||
msg: "Error general de activation"
|
||||
}
|
||||
}).send()
|
||||
return;
|
||||
}
|
||||
}
|
||||
return this.controllerGenerator<{ iccid: string, offer: string }, { iccid: string, offer: string, compañia: string }>({
|
||||
validator: activationValidator,
|
||||
mapBody: (b) => {
|
||||
const { iccid, offer } = b
|
||||
const compañia = companyFromIccid(iccid)
|
||||
return { iccid, compañia, offer }
|
||||
},
|
||||
useCase: (args) => this.simUseCases.preActivation(args),
|
||||
onError: (d, e) => console.error("[x] Error preactivation: ", d, e),
|
||||
onSuccess: console.log
|
||||
})
|
||||
}
|
||||
|
||||
public activation() {
|
||||
return async (req: Request, res: Response) => {
|
||||
try {
|
||||
activationValidator.validate(req.body)
|
||||
} catch (e) {
|
||||
res.status(422).json({
|
||||
errors: {
|
||||
msg: e
|
||||
}
|
||||
})
|
||||
console.error("[!] Error validando mensaje")
|
||||
return;
|
||||
}
|
||||
|
||||
const { iccid, offer } = req.body
|
||||
|
||||
const compañia = companyFromIccid(iccid)
|
||||
|
||||
if (compañia == undefined) {
|
||||
res.status(500).json({
|
||||
errors: {
|
||||
msg: "El iccid no pertenece a una compañia conocida"
|
||||
}
|
||||
})
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
try {
|
||||
await this.simUseCases.activation({ iccid, compañia, offer })
|
||||
|
||||
res.status(200).json({
|
||||
iccid: iccid,
|
||||
operation: "activation"
|
||||
}).send()
|
||||
return;
|
||||
|
||||
} catch (err) {
|
||||
console.error("Error activando la sim ", req.body)
|
||||
res.status(500).json({
|
||||
errors: {
|
||||
msg: "Error general de activation"
|
||||
}
|
||||
}).send()
|
||||
return;
|
||||
}
|
||||
}
|
||||
return this.controllerGenerator<{ iccid: string, offer: string }, { iccid: string, offer: string, compañia: string }>({
|
||||
validator: activationValidator,
|
||||
mapBody: (b) => {
|
||||
const { iccid, offer } = b
|
||||
const compañia = companyFromIccid(iccid)
|
||||
return { iccid, compañia, offer }
|
||||
},
|
||||
useCase: (args) => this.simUseCases.activation(args),
|
||||
onError: (d, e) => console.error("[x] Error activacion: ", d, e),
|
||||
onSuccess: console.log
|
||||
})
|
||||
}
|
||||
|
||||
public cancelation() {
|
||||
return async (req: Request, res: Response) => {
|
||||
try {
|
||||
iccidValidator.validate(req.body)
|
||||
} catch (e) {
|
||||
res.status(422).json({
|
||||
errors: {
|
||||
msg: e
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
const { iccid } = req.body
|
||||
const compañia = companyFromIccid(iccid)
|
||||
|
||||
try {
|
||||
await this.simUseCases.cancelation({ iccid, compañia })
|
||||
res.status(200).json({
|
||||
iccid: iccid,
|
||||
operation: "cancelation"
|
||||
})
|
||||
} catch (err) {
|
||||
console.error("Error cancelando la sim ", req.body)
|
||||
res.status(500).json({
|
||||
errors: {
|
||||
msg: "Error general de cancelacion"
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
return this.controllerGenerator<{ iccid: string }, { iccid: string, compañia: string }>({
|
||||
validator: iccidValidator,
|
||||
mapBody: (b) => {
|
||||
const { iccid } = b
|
||||
const compañia = companyFromIccid(iccid)
|
||||
return { iccid, compañia }
|
||||
},
|
||||
useCase: (args) => this.simUseCases.cancelation(args),
|
||||
// TODO: Meter en los mensajes el nombre de la operacion
|
||||
onError: (d, e) => console.error("[x] Error cancelacion: ", d, e),
|
||||
onSuccess: console.log
|
||||
})
|
||||
}
|
||||
|
||||
public pause() {
|
||||
return async (req: Request, res: Response) => {
|
||||
try {
|
||||
iccidValidator.validate(req.body)
|
||||
} catch (e) {
|
||||
res.status(422).json({
|
||||
errors: {
|
||||
msg: e
|
||||
}
|
||||
})
|
||||
}
|
||||
return this.controllerGenerator<{ iccid: string }, { iccid: string, compañia: string }>({
|
||||
validator: iccidValidator,
|
||||
mapBody: (b) => {
|
||||
const { iccid } = b
|
||||
const compañia = companyFromIccid(iccid)
|
||||
return { iccid, compañia }
|
||||
},
|
||||
useCase: (args) => this.simUseCases.pause(args),
|
||||
onError: (d, e) => console.error("[x] Error pausa: ", d, e),
|
||||
onSuccess: console.log
|
||||
})
|
||||
|
||||
const { iccid } = req.body
|
||||
const compañia = companyFromIccid(iccid)
|
||||
|
||||
try {
|
||||
await this.simUseCases.pause({ iccid, compañia })
|
||||
res.status(200).json({
|
||||
iccid: iccid,
|
||||
operation: "cancelation"
|
||||
})
|
||||
} catch (err) {
|
||||
console.error("Error pausando la sim ", req.body)
|
||||
res.status(500).json({
|
||||
errors: {
|
||||
msg: "Error pausando la sim"
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public free() {
|
||||
|
||||
@@ -24,7 +24,7 @@ export class SimUsecases {
|
||||
}
|
||||
|
||||
/**
|
||||
* Añade un id de mensaje (correlation_id en ala base de datos)
|
||||
* Añade un id de mensaje (correlation_id en la base de datos) a los mensajes que van a entrar en la cola
|
||||
*/
|
||||
private addMessage_id(event: SimEvents.general): SimEvents.general & { headers: { message_id: string } } {
|
||||
const uuid = uuidv7()
|
||||
@@ -65,7 +65,6 @@ export class SimUsecases {
|
||||
|
||||
const result = await this.orderRepository.createOrder<T>(order)
|
||||
return result;
|
||||
|
||||
}
|
||||
|
||||
async test(args: { iccid: string }) {
|
||||
@@ -84,7 +83,7 @@ export class SimUsecases {
|
||||
}
|
||||
|
||||
/**
|
||||
* WIP
|
||||
* TODO:
|
||||
* Crea una nueva sim de la que no se tenia registro anteriormente
|
||||
* Si ya existia se modifican los campos pero no se hace un cambio
|
||||
* de estado.
|
||||
@@ -101,8 +100,8 @@ export class SimUsecases {
|
||||
return this.eventBus.publish([activationEvent])
|
||||
}
|
||||
|
||||
async activation(args: { iccid: string, compañia: string, offer: string }) {
|
||||
|
||||
async activation(args: { iccid: string, compañia: string, offer: string }):
|
||||
Promise<Result<string, { iccid: string, message_id: string, operation: "activation" }>> {
|
||||
const activationEvent = <SimEvents.activation>{
|
||||
key: `sim.${args.compañia}.activate`,
|
||||
payload: {
|
||||
@@ -110,14 +109,29 @@ export class SimUsecases {
|
||||
offer: args.offer
|
||||
}
|
||||
}
|
||||
|
||||
const activationWithId = this.addMessage_id(activationEvent)
|
||||
console.log("[d] Activation ", activationWithId)
|
||||
await this.eventBus.publish([activationWithId])
|
||||
await this.saveOrder(activationWithId)
|
||||
const createdOrder = await this.saveOrder<SimEvents.activation>(activationWithId)
|
||||
|
||||
if (createdOrder.error != undefined) {
|
||||
console.error(createdOrder.error)
|
||||
return {
|
||||
error: createdOrder.error
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
data: {
|
||||
iccid: args.iccid,
|
||||
operation: "activation",
|
||||
message_id: createdOrder.data?.correlation_id
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async preActivation(args: { iccid: string, compañia: string }) {
|
||||
async preActivation(args: { iccid: string, compañia: string }):
|
||||
Promise<Result<string, { iccid: string, message_id: string, operation: "preactivation" }>> {
|
||||
|
||||
const preActivationEvent = <SimEvents.preActivation>{
|
||||
key: `sim.${args.compañia}.preActivate`,
|
||||
@@ -126,13 +140,30 @@ export class SimUsecases {
|
||||
}
|
||||
}
|
||||
console.log("[d] Pre - activation ", preActivationEvent)
|
||||
return this.eventBus.publish([preActivationEvent])
|
||||
await this.eventBus.publish([preActivationEvent])
|
||||
const preactivationWithId = this.addMessage_id(preActivationEvent)
|
||||
const createdOrder = await this.saveOrder<SimEvents.preActivation>(preactivationWithId)
|
||||
if (createdOrder.error != undefined) {
|
||||
console.error(createdOrder.error)
|
||||
return {
|
||||
error: createdOrder.error
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
data: {
|
||||
iccid: args.iccid,
|
||||
operation: "preactivation",
|
||||
message_id: createdOrder.data?.correlation_id
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Para objenious es terminate
|
||||
*/
|
||||
async cancelation(args: { iccid: string, compañia: string }) {
|
||||
async cancelation(args: { iccid: string, compañia: string }):
|
||||
Promise<Result<string, { iccid: string, message_id: string, operation: "cancelation" }>> {
|
||||
|
||||
const cancelationEvent = <SimEvents.cancel>{
|
||||
key: `sim.${args.compañia}.cancel`,
|
||||
@@ -144,8 +175,21 @@ export class SimUsecases {
|
||||
const cancelationWithId = this.addMessage_id(cancelationEvent)
|
||||
console.log("[d] Cancelation ", cancelationWithId)
|
||||
await this.eventBus.publish([cancelationWithId])
|
||||
await this.saveOrder(cancelationWithId)
|
||||
return cancelationWithId
|
||||
const savedOrder = await this.saveOrder(cancelationWithId)
|
||||
if (savedOrder.error != undefined) {
|
||||
console.error(savedOrder.error)
|
||||
return {
|
||||
error: savedOrder.error
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
data: {
|
||||
iccid: args.iccid,
|
||||
message_id: savedOrder.data.correlation_id,
|
||||
operation: "cancelation"
|
||||
}
|
||||
}
|
||||
}
|
||||
// alias por si acaso
|
||||
public terminate = this.cancelation;
|
||||
@@ -153,7 +197,8 @@ export class SimUsecases {
|
||||
/**
|
||||
* alias de bloquear / suspender en objenious
|
||||
*/
|
||||
async pause(args: { iccid: string, compañia: string }) {
|
||||
async pause(args: { iccid: string, compañia: string }):
|
||||
Promise<Result<string, { iccid: string, message_id: string, operation: "cancelation" }>> {
|
||||
const pauseEvent = <SimEvents.pause>{
|
||||
key: `sim.${args.compañia}.pause`,
|
||||
payload: {
|
||||
@@ -161,10 +206,25 @@ export class SimUsecases {
|
||||
}
|
||||
}
|
||||
const pauseWithId = this.addMessage_id(pauseEvent)
|
||||
console.log("[d] Cancelation ", pauseWithId)
|
||||
console.log("[d] Pause", pauseWithId)
|
||||
await this.eventBus.publish([pauseWithId])
|
||||
await this.saveOrder(pauseWithId)
|
||||
return pauseWithId
|
||||
const savedOrder = await this.saveOrder(pauseWithId)
|
||||
|
||||
if (savedOrder.error != undefined) {
|
||||
console.error(savedOrder.error)
|
||||
return {
|
||||
error: savedOrder.error
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
data: {
|
||||
iccid: args.iccid,
|
||||
message_id: savedOrder.data.correlation_id,
|
||||
operation: "cancelation"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async free(args: { iccid: string, compañia: string }) {
|
||||
|
||||
@@ -8,9 +8,10 @@ describe("test validators", () => {
|
||||
iccid: "8933201125068886692"
|
||||
}
|
||||
const res = iccidValidator.validate(validBody)
|
||||
assert(res == true)
|
||||
assert(res.error == undefined)
|
||||
}),
|
||||
|
||||
// TODO: Nada de esto es valido, a partir de ahora los validadores no lanzan excepcion sino Result
|
||||
it("shouldnt validate empty string iccid", () => {
|
||||
const validBody = {
|
||||
iccid: ""
|
||||
|
||||
@@ -3,7 +3,9 @@ import { BodyValidator, Validator } from "sim-shared/aplication/BodyValidator.js
|
||||
|
||||
const offers = new Map([
|
||||
["mensual", "SAVEFAMILY1"],
|
||||
["anual", "SAVEFAMILY2"]
|
||||
["anual", "SAVEFAMILY2"],
|
||||
["SAVEFAMILY1", "SAVEFAMILY1"],
|
||||
["SAVEFAMILY2", "SAVEFAMILY2"],
|
||||
])
|
||||
|
||||
const iccidLongitudValidator = <Validator<{ iccid: string }>>{
|
||||
|
||||
@@ -46,5 +46,4 @@ if (env.ENVIRONMENT == "production") {
|
||||
assert(env.RABBITMQ_HOST != "localhost")
|
||||
}
|
||||
|
||||
console.log("CRON: ENV", env)
|
||||
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
import { Result } from "../domain/Result.js"
|
||||
|
||||
export type Validator<T extends Object> = {
|
||||
field: keyof T,
|
||||
errorMsg: string,
|
||||
@@ -16,10 +18,18 @@ export class BodyValidator<T extends Object> {
|
||||
this.validatorList = validators
|
||||
}
|
||||
|
||||
public validate(obj: T) {
|
||||
public validate(obj: T): Result<{ msg: string, field: string }, boolean> {
|
||||
for (const validator of this.validatorList) {
|
||||
if (validator.validationFunc(obj) == false) throw new Error(validator.errorMsg)
|
||||
if (validator.validationFunc(obj) == false)
|
||||
return {
|
||||
error: {
|
||||
msg: validator.errorMsg,
|
||||
field: String(validator.field)
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
return {
|
||||
data: true
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,14 +1,31 @@
|
||||
|
||||
export type Success<D> = {
|
||||
error?: undefined | null,
|
||||
data: D
|
||||
}
|
||||
|
||||
export type Failure<E = Error> = {
|
||||
data?: undefined | null,
|
||||
error: E
|
||||
}
|
||||
|
||||
/**
|
||||
* Result<Error,Data>
|
||||
*/
|
||||
export type Result<E, D> =
|
||||
{
|
||||
error: E,
|
||||
data?: undefined
|
||||
}
|
||||
|
|
||||
{
|
||||
error?: undefined,
|
||||
data: D
|
||||
}
|
||||
export type Result<E, D> = Failure<E> | Success<D>
|
||||
|
||||
export async function tryCatch<T>(func: Promise<T>): Promise<Result<{ msg: Error }, T>> {
|
||||
try {
|
||||
const res = await func;
|
||||
return {
|
||||
data: res
|
||||
}
|
||||
} catch (e: unknown) {
|
||||
return {
|
||||
error: {
|
||||
msg: e as Error
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
156
yarn.lock
156
yarn.lock
@@ -187,6 +187,15 @@ __metadata:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"@gar/promise-retry@npm:^1.0.0":
|
||||
version: 1.0.2
|
||||
resolution: "@gar/promise-retry@npm:1.0.2"
|
||||
dependencies:
|
||||
retry: "npm:^0.13.1"
|
||||
checksum: 10/b91326999ce94677cbe91973079eabc689761a93a045f6a2d34d4070e9305b27f6c54e4021688c7080cb14caf89eafa0c0f300af741b94c20d18608bdb66ca46
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"@isaacs/fs-minipass@npm:^4.0.0":
|
||||
version: 4.0.1
|
||||
resolution: "@isaacs/fs-minipass@npm:4.0.1"
|
||||
@@ -563,22 +572,22 @@ __metadata:
|
||||
linkType: hard
|
||||
|
||||
"@types/node@npm:*, @types/node@npm:^25.0.3":
|
||||
version: 25.3.0
|
||||
resolution: "@types/node@npm:25.3.0"
|
||||
version: 25.3.3
|
||||
resolution: "@types/node@npm:25.3.3"
|
||||
dependencies:
|
||||
undici-types: "npm:~7.18.0"
|
||||
checksum: 10/061b00c8de070a606a052afaa4c45dca5f8d6a8e7e39c0c3e196bb650ee37e986bbb161991ea39076a05aada102f36b13c974528448a09efd8d36bdfee75de4b
|
||||
checksum: 10/883e8942b0ddf89f9aae56c4205af8d9a368acd6cab83aa052447a6c5e69ce2bc8ab3f54e549233ada160ba9216dad7f30c62c35867c584fe844ae99f7dea2e0
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"@types/pg@npm:^8.16.0":
|
||||
version: 8.16.0
|
||||
resolution: "@types/pg@npm:8.16.0"
|
||||
version: 8.18.0
|
||||
resolution: "@types/pg@npm:8.18.0"
|
||||
dependencies:
|
||||
"@types/node": "npm:*"
|
||||
pg-protocol: "npm:*"
|
||||
pg-types: "npm:^2.2.0"
|
||||
checksum: 10/c03346fbe87728a237f30a3d0a436b86ede88e1dc471782bf679a4d74d67ee2a96f953e7c04d73841d21b9db43a5bf2ccdf2cd4c75450ea57efd947049809b3a
|
||||
checksum: 10/fdfcaff97f0bd067bf4c4750592bd627a772c5ac4d4164332efe121f9fc2112479dcf913bafd91fe8e86581d5994897e5fd5b4faaf734a42719540037d3b64e7
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
@@ -627,7 +636,17 @@ __metadata:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"@types/supertest@npm:*, @types/supertest@npm:^6.0.3":
|
||||
"@types/supertest@npm:*":
|
||||
version: 7.2.0
|
||||
resolution: "@types/supertest@npm:7.2.0"
|
||||
dependencies:
|
||||
"@types/methods": "npm:^1.1.4"
|
||||
"@types/superagent": "npm:^8.1.0"
|
||||
checksum: 10/5a322e29b81033e90ac50ab315d49559b21809ee39b5681ab7386819463e30d68e29c63c946023a1c353e7f13fb3f20d64dcb89d3d8a0fff569450501aff786c
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"@types/supertest@npm:^6.0.3":
|
||||
version: 6.0.3
|
||||
resolution: "@types/supertest@npm:6.0.3"
|
||||
dependencies:
|
||||
@@ -769,7 +788,7 @@ __metadata:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"ansi-regex@npm:^6.0.1":
|
||||
"ansi-regex@npm:^6.2.2":
|
||||
version: 6.2.2
|
||||
resolution: "ansi-regex@npm:6.2.2"
|
||||
checksum: 10/9b17ce2c6daecc75bcd5966b9ad672c23b184dc3ed9bf3c98a0702f0d2f736c15c10d461913568f2cf527a5e64291c7473358885dd493305c84a1cfed66ba94f
|
||||
@@ -845,13 +864,13 @@ __metadata:
|
||||
linkType: hard
|
||||
|
||||
"axios@npm:^1.13.3":
|
||||
version: 1.13.5
|
||||
resolution: "axios@npm:1.13.5"
|
||||
version: 1.13.6
|
||||
resolution: "axios@npm:1.13.6"
|
||||
dependencies:
|
||||
follow-redirects: "npm:^1.15.11"
|
||||
form-data: "npm:^4.0.5"
|
||||
proxy-from-env: "npm:^1.1.0"
|
||||
checksum: 10/db726d09902565ef9a0632893530028310e2ec2b95b727114eca1b101450b00014133dfc3871cffc87983fb922bca7e4874d7e2826d1550a377a157cdf3f05b6
|
||||
checksum: 10/a7ed83c2af3ef21d64609df0f85e76893a915a864c5934df69241001d0578082d6521a0c730bf37518ee458821b5695957cb10db9fc705f2a8996c8686ea7a89
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
@@ -887,11 +906,11 @@ __metadata:
|
||||
linkType: hard
|
||||
|
||||
"brace-expansion@npm:^5.0.2":
|
||||
version: 5.0.3
|
||||
resolution: "brace-expansion@npm:5.0.3"
|
||||
version: 5.0.4
|
||||
resolution: "brace-expansion@npm:5.0.4"
|
||||
dependencies:
|
||||
balanced-match: "npm:^4.0.2"
|
||||
checksum: 10/8ba7deae4ca333d52418d2cde3287ac23f44f7330d92c3ecd96a8941597bea8aab02227bd990944d6711dd549bcc6e550fe70be5d94aa02e2fdc88942f480c9b
|
||||
checksum: 10/cfd57e20d8ded9578149e47ae4d3fff2b2f78d06b54a32a73057bddff65c8e9b930613f0cbcfefedf12dd117151e19d4da16367d5127c54f3bff02d8a4479bb2
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
@@ -1123,9 +1142,9 @@ __metadata:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"db-migrate@https://git.savefamilygps.net/alvarsanmartin/herramienta-migracion.git":
|
||||
"db-migrate@http://gitea:3000/alvarsanmartin/herramienta-migracion.git":
|
||||
version: 1.1.0
|
||||
resolution: "db-migrate@https://git.savefamilygps.net/alvarsanmartin/herramienta-migracion.git#commit=f84d68ba79161b9b06b747919979db00aac34b49"
|
||||
resolution: "db-migrate@http://gitea:3000/alvarsanmartin/herramienta-migracion.git#commit=f84d68ba79161b9b06b747919979db00aac34b49"
|
||||
dependencies:
|
||||
pg: "npm:^8.18.0"
|
||||
yargs: "npm:^18.0.0"
|
||||
@@ -1226,15 +1245,6 @@ __metadata:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"encoding@npm:^0.1.13":
|
||||
version: 0.1.13
|
||||
resolution: "encoding@npm:0.1.13"
|
||||
dependencies:
|
||||
iconv-lite: "npm:^0.6.2"
|
||||
checksum: 10/bb98632f8ffa823996e508ce6a58ffcf5856330fde839ae42c9e1f436cc3b5cc651d4aeae72222916545428e54fd0f6aa8862fd8d25bdbcc4589f1e3f3715e7f
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"env-paths@npm:^2.2.0":
|
||||
version: 2.2.1
|
||||
resolution: "env-paths@npm:2.2.1"
|
||||
@@ -1242,13 +1252,6 @@ __metadata:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"err-code@npm:^2.0.2":
|
||||
version: 2.0.3
|
||||
resolution: "err-code@npm:2.0.3"
|
||||
checksum: 10/1d20d825cdcce8d811bfbe86340f4755c02655a7feb2f13f8c880566d9d72a3f6c92c192a6867632e490d6da67b678271f46e01044996a6443e870331100dfdd
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"es-define-property@npm:^1.0.1":
|
||||
version: 1.0.1
|
||||
resolution: "es-define-property@npm:1.0.1"
|
||||
@@ -1795,16 +1798,7 @@ __metadata:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"iconv-lite@npm:^0.6.2":
|
||||
version: 0.6.3
|
||||
resolution: "iconv-lite@npm:0.6.3"
|
||||
dependencies:
|
||||
safer-buffer: "npm:>= 2.1.2 < 3.0.0"
|
||||
checksum: 10/24e3292dd3dadaa81d065c6f8c41b274a47098150d444b96e5f53b4638a9a71482921ea6a91a1f59bb71d9796de25e04afd05919fa64c360347ba65d3766f10f
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"iconv-lite@npm:^0.7.0, iconv-lite@npm:~0.7.0":
|
||||
"iconv-lite@npm:^0.7.0, iconv-lite@npm:^0.7.2, iconv-lite@npm:~0.7.0":
|
||||
version: 0.7.2
|
||||
resolution: "iconv-lite@npm:0.7.2"
|
||||
dependencies:
|
||||
@@ -1918,9 +1912,10 @@ __metadata:
|
||||
linkType: hard
|
||||
|
||||
"make-fetch-happen@npm:^15.0.0":
|
||||
version: 15.0.3
|
||||
resolution: "make-fetch-happen@npm:15.0.3"
|
||||
version: 15.0.4
|
||||
resolution: "make-fetch-happen@npm:15.0.4"
|
||||
dependencies:
|
||||
"@gar/promise-retry": "npm:^1.0.0"
|
||||
"@npmcli/agent": "npm:^4.0.0"
|
||||
cacache: "npm:^20.0.1"
|
||||
http-cache-semantics: "npm:^4.1.1"
|
||||
@@ -1930,9 +1925,8 @@ __metadata:
|
||||
minipass-pipeline: "npm:^1.2.4"
|
||||
negotiator: "npm:^1.0.0"
|
||||
proc-log: "npm:^6.0.0"
|
||||
promise-retry: "npm:^2.0.1"
|
||||
ssri: "npm:^13.0.0"
|
||||
checksum: 10/78da4fc1df83cb596e2bae25aa0653b8a9c6cbdd6674a104894e03be3acfcd08c70b78f06ef6407fbd6b173f6a60672480d78641e693d05eb71c09c13ee35278
|
||||
checksum: 10/4aa75baab500eff4259f2e1a3e76cf01ab3a3cd750037e4bd7b5e22bc5a60f12cc766b3c45e6288accb5ab609e88de5019a8014e0f96f6594b7b03cb504f4b81
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
@@ -2023,11 +2017,11 @@ __metadata:
|
||||
linkType: hard
|
||||
|
||||
"minimatch@npm:^10.2.2":
|
||||
version: 10.2.2
|
||||
resolution: "minimatch@npm:10.2.2"
|
||||
version: 10.2.4
|
||||
resolution: "minimatch@npm:10.2.4"
|
||||
dependencies:
|
||||
brace-expansion: "npm:^5.0.2"
|
||||
checksum: 10/e135be7b502ac97c02bcee42ccc1c55dc26dbac036c0f4acde69e42fe339d7fb53fae711e57b3546cb533426382ea492c73a073c7f78832e0453d120d48dd015
|
||||
checksum: 10/aea4874e521c55bb60744685bbffe3d152e5460f84efac3ea936e6bbe2ceba7deb93345fec3f9bb17f7b6946776073a64d40ae32bf5f298ad690308121068a1f
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
@@ -2041,17 +2035,17 @@ __metadata:
|
||||
linkType: hard
|
||||
|
||||
"minipass-fetch@npm:^5.0.0":
|
||||
version: 5.0.1
|
||||
resolution: "minipass-fetch@npm:5.0.1"
|
||||
version: 5.0.2
|
||||
resolution: "minipass-fetch@npm:5.0.2"
|
||||
dependencies:
|
||||
encoding: "npm:^0.1.13"
|
||||
iconv-lite: "npm:^0.7.2"
|
||||
minipass: "npm:^7.0.3"
|
||||
minipass-sized: "npm:^2.0.0"
|
||||
minizlib: "npm:^3.0.1"
|
||||
dependenciesMeta:
|
||||
encoding:
|
||||
iconv-lite:
|
||||
optional: true
|
||||
checksum: 10/08bf0c9866e7f344bf1863ce0d99c0a6fe96b43ef5a4119e23d84a21e613a3f55ecf302adf28d9e228b4ebd50e81d5e84c397e0535089090427319379f478d94
|
||||
checksum: 10/4f3f65ea5b20a3a287765ebf21cc73e62031f754944272df2a3039296cc75a8fc2dc50b8a3c4f39ce3ac6e5cc583e8dc664d12c6ab98e0883d263e49f344bc86
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
@@ -2287,19 +2281,19 @@ __metadata:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"pg-pool@npm:^3.11.0":
|
||||
version: 3.11.0
|
||||
resolution: "pg-pool@npm:3.11.0"
|
||||
"pg-pool@npm:^3.12.0":
|
||||
version: 3.12.0
|
||||
resolution: "pg-pool@npm:3.12.0"
|
||||
peerDependencies:
|
||||
pg: ">=8.0"
|
||||
checksum: 10/51c77d99f17cf791333467352df8326e0f70f9c517eada65a5e7819b2422f6e655e52319f5406eb578504442ae5f399b6e1d023e41d0c199aaf82879a890db6d
|
||||
checksum: 10/81a4220b89ba28034c51db0a7e231a8c1555ddb3cf8bacde0acd092fb26473763a335629ffcf5153059dd8f406d39610e384fd9176d34359a3d1498b4c5b95cd
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"pg-protocol@npm:*, pg-protocol@npm:^1.11.0":
|
||||
version: 1.11.0
|
||||
resolution: "pg-protocol@npm:1.11.0"
|
||||
checksum: 10/a70b1b4a3fc5b1be80dfdd65c829a149b8bd9df7488f9c47e0b51c9413aec5eb6da0a9ae9812891d74cd9f2ee90c0e391984a41b64603e7375fcbb9e07070b08
|
||||
"pg-protocol@npm:*, pg-protocol@npm:^1.12.0":
|
||||
version: 1.12.0
|
||||
resolution: "pg-protocol@npm:1.12.0"
|
||||
checksum: 10/0f5d8a5dbef39ef4d06686910ad61599b8d26c4505e76af2f6da3a1a1028c312f61678fae5e5012d477fe318b5ebc8507a828c087973b22e5fd4ec1e7394101a
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
@@ -2317,13 +2311,13 @@ __metadata:
|
||||
linkType: hard
|
||||
|
||||
"pg@npm:^8.18.0":
|
||||
version: 8.18.0
|
||||
resolution: "pg@npm:8.18.0"
|
||||
version: 8.19.0
|
||||
resolution: "pg@npm:8.19.0"
|
||||
dependencies:
|
||||
pg-cloudflare: "npm:^1.3.0"
|
||||
pg-connection-string: "npm:^2.11.0"
|
||||
pg-pool: "npm:^3.11.0"
|
||||
pg-protocol: "npm:^1.11.0"
|
||||
pg-pool: "npm:^3.12.0"
|
||||
pg-protocol: "npm:^1.12.0"
|
||||
pg-types: "npm:2.2.0"
|
||||
pgpass: "npm:1.0.5"
|
||||
peerDependencies:
|
||||
@@ -2334,7 +2328,7 @@ __metadata:
|
||||
peerDependenciesMeta:
|
||||
pg-native:
|
||||
optional: true
|
||||
checksum: 10/91c622f179f60df08ab7aa9b05a890567ea47f2d7984377b64e88e1eba1c42787324b7fc5ff00e109a757f3329dc4b57c73502603ae2765d1827b2082abbdcfa
|
||||
checksum: 10/0d552512b6c65c20b4054a203632f8ad51f6c5e60b8aaf65f5dc9f07a698da1e8974ca3918964999ea783c370bda9d230e662d2bab333b3968a28086923934e0
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
@@ -2441,16 +2435,6 @@ __metadata:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"promise-retry@npm:^2.0.1":
|
||||
version: 2.0.1
|
||||
resolution: "promise-retry@npm:2.0.1"
|
||||
dependencies:
|
||||
err-code: "npm:^2.0.2"
|
||||
retry: "npm:^0.12.0"
|
||||
checksum: 10/96e1a82453c6c96eef53a37a1d6134c9f2482f94068f98a59145d0986ca4e497bf110a410adf73857e588165eab3899f0ebcf7b3890c1b3ce802abc0d65967d4
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"proxy-addr@npm:^2.0.7":
|
||||
version: 2.0.7
|
||||
resolution: "proxy-addr@npm:2.0.7"
|
||||
@@ -2547,10 +2531,10 @@ __metadata:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"retry@npm:^0.12.0":
|
||||
version: 0.12.0
|
||||
resolution: "retry@npm:0.12.0"
|
||||
checksum: 10/1f914879f97e7ee931ad05fe3afa629bd55270fc6cf1c1e589b6a99fab96d15daad0fa1a52a00c729ec0078045fe3e399bd4fd0c93bcc906957bdc17f89cb8e6
|
||||
"retry@npm:^0.13.1":
|
||||
version: 0.13.1
|
||||
resolution: "retry@npm:0.13.1"
|
||||
checksum: 10/6125ec2e06d6e47e9201539c887defba4e47f63471db304c59e4b82fc63c8e89ca06a77e9d34939a9a42a76f00774b2f46c0d4a4cbb3e287268bd018ed69426d
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
@@ -2884,7 +2868,7 @@ __metadata:
|
||||
axios: "npm:^1.13.3"
|
||||
concurrently: "npm:^9.2.1"
|
||||
cors: "npm:^2.8.5"
|
||||
db-migrate: "https://git.savefamilygps.net/alvarsanmartin/herramienta-migracion.git"
|
||||
db-migrate: "http://gitea:3000/alvarsanmartin/herramienta-migracion.git"
|
||||
dotenv: "npm:^17.2.3"
|
||||
express: "npm:^5.2.1"
|
||||
pg: "npm:^8.18.0"
|
||||
@@ -3079,11 +3063,11 @@ __metadata:
|
||||
linkType: hard
|
||||
|
||||
"strip-ansi@npm:^7.1.0":
|
||||
version: 7.1.2
|
||||
resolution: "strip-ansi@npm:7.1.2"
|
||||
version: 7.2.0
|
||||
resolution: "strip-ansi@npm:7.2.0"
|
||||
dependencies:
|
||||
ansi-regex: "npm:^6.0.1"
|
||||
checksum: 10/db0e3f9654e519c8a33c50fc9304d07df5649388e7da06d3aabf66d29e5ad65d5e6315d8519d409c15b32fa82c1df7e11ed6f8cd50b0e4404463f0c9d77c8d0b
|
||||
ansi-regex: "npm:^6.2.2"
|
||||
checksum: 10/96da3bc6d73cfba1218625a3d66cf7d37a69bf0920d8735b28f9eeaafcdb6c1fe8440e1ae9eb1ba0ca355dbe8702da872e105e2e939fa93e7851b3cb5dd7d316
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
|
||||
Reference in New Issue
Block a user