Fix
This commit is contained in:
3
.env
3
.env
@@ -27,3 +27,6 @@ PGHOST=localhost
|
|||||||
PGUSER=alvar
|
PGUSER=alvar
|
||||||
PGPASSWORD=alvar
|
PGPASSWORD=alvar
|
||||||
PGPORT=5433
|
PGPORT=5433
|
||||||
|
|
||||||
|
# Proxy
|
||||||
|
SIMCONNECTIONSURL=http://sim-connections.savefamilygps.net
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ post {
|
|||||||
}
|
}
|
||||||
|
|
||||||
body:form-urlencoded {
|
body:form-urlencoded {
|
||||||
iccid: 8933201125068890694
|
iccid: 8933201125068890408
|
||||||
offer: SAVEFAMILY1
|
offer: SAVEFAMILY1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ post {
|
|||||||
}
|
}
|
||||||
|
|
||||||
body:form-urlencoded {
|
body:form-urlencoded {
|
||||||
iccid: 8933201125068887864
|
iccid: 8933201125068890074
|
||||||
}
|
}
|
||||||
|
|
||||||
settings {
|
settings {
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ export class SimRouter {
|
|||||||
["activate", this.simController.activate()],
|
["activate", this.simController.activate()],
|
||||||
["pause", this.simController.suspend()],
|
["pause", this.simController.suspend()],
|
||||||
["cancel", this.simController.terminate()],
|
["cancel", this.simController.terminate()],
|
||||||
["reActivate", this.simController.reActivate()],
|
["reactivation", this.simController.reActivate()],
|
||||||
["preActivate", this.simController.preActivate()]
|
["preActivate", this.simController.preActivate()]
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -131,6 +131,20 @@ export class SimController {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public reActivation() {
|
||||||
|
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.reActivation(args),
|
||||||
|
onError: (d, e) => console.error("[x] Error activacion: ", d, e),
|
||||||
|
onSuccess: console.log
|
||||||
|
})
|
||||||
|
}
|
||||||
public cancelation() {
|
public cancelation() {
|
||||||
return this.controllerGenerator<{ iccid: string }, { iccid: string, compañia: string }>({
|
return this.controllerGenerator<{ iccid: string }, { iccid: string, compañia: string }>({
|
||||||
validator: iccidValidator,
|
validator: iccidValidator,
|
||||||
|
|||||||
@@ -130,6 +130,36 @@ export class SimUsecases {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async reActivation(args: { iccid: string, compañia: string, offer: string }):
|
||||||
|
Promise<Result<string, { iccid: string, message_id: string, operation: "reactivation" }>> {
|
||||||
|
const activationEvent = <SimEvents.activation>{
|
||||||
|
key: `sim.${args.compañia}.reactivation`,
|
||||||
|
payload: {
|
||||||
|
iccid: args.iccid,
|
||||||
|
offer: args.offer
|
||||||
|
}
|
||||||
|
}
|
||||||
|
const activationWithId = this.addMessage_id(activationEvent)
|
||||||
|
console.log("[d] Reactivation ", activationWithId)
|
||||||
|
await this.eventBus.publish([activationWithId])
|
||||||
|
const createdOrder = await this.saveOrder<SimEvents.reActivation>(activationWithId)
|
||||||
|
|
||||||
|
if (createdOrder.error != undefined) {
|
||||||
|
console.error(createdOrder.error)
|
||||||
|
return {
|
||||||
|
error: createdOrder.error
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
data: {
|
||||||
|
iccid: args.iccid,
|
||||||
|
operation: "reactivation",
|
||||||
|
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" }>> {
|
Promise<Result<string, { iccid: string, message_id: string, operation: "preactivation" }>> {
|
||||||
|
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import { simRoutes } from "./infrastructure/simRoutes.http.js"
|
|||||||
import { rabbitmqEventBus } from '#config/eventBusConfig.js';
|
import { rabbitmqEventBus } from '#config/eventBusConfig.js';
|
||||||
import { env } from "#config/env/index.js"
|
import { env } from "#config/env/index.js"
|
||||||
import { orderRoutes } from "#adapters/orderRoutes.http.js";
|
import { orderRoutes } from "#adapters/orderRoutes.http.js";
|
||||||
|
import { connectionsRoutes } from "#adapters/simconnectionsRoutes.js";
|
||||||
|
|
||||||
const PORT = env.API_PORT
|
const PORT = env.API_PORT
|
||||||
const HOSTNAME = "0.0.0.0"
|
const HOSTNAME = "0.0.0.0"
|
||||||
@@ -26,6 +27,7 @@ app.use(express.json());
|
|||||||
app.use(express.urlencoded({ extended: true }));
|
app.use(express.urlencoded({ extended: true }));
|
||||||
|
|
||||||
app.use("/sim", simRoutes)
|
app.use("/sim", simRoutes)
|
||||||
|
app.use("/simconnections", connectionsRoutes)
|
||||||
app.use("/orders", orderRoutes)
|
app.use("/orders", orderRoutes)
|
||||||
|
|
||||||
app.use("/docs", express.static(path.join(process.cwd(), '../../docs')))
|
app.use("/docs", express.static(path.join(process.cwd(), '../../docs')))
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ simRoutes.get("/status", () => { })
|
|||||||
simRoutes.post("/save", simController.save())
|
simRoutes.post("/save", simController.save())
|
||||||
|
|
||||||
simRoutes.post("/activate", simController.activation())
|
simRoutes.post("/activate", simController.activation())
|
||||||
|
simRoutes.post("/reActivate", simController.reActivation())
|
||||||
|
|
||||||
simRoutes.post("/preActivate", simController.preactivation())
|
simRoutes.post("/preActivate", simController.preactivation())
|
||||||
|
|
||||||
@@ -36,11 +37,4 @@ simRoutes.post("/test", simController.test())
|
|||||||
simRoutes.post("/free", simController.free())
|
simRoutes.post("/free", simController.free())
|
||||||
|
|
||||||
|
|
||||||
// Proxy
|
|
||||||
|
|
||||||
//const proxySimConnections =
|
|
||||||
|
|
||||||
// simRoutes.post("/simconnections/sim/activate")
|
|
||||||
//simRoutes.post("/simconnections/sim/pause")
|
|
||||||
|
|
||||||
export { simRoutes }
|
export { simRoutes }
|
||||||
|
|||||||
@@ -0,0 +1,20 @@
|
|||||||
|
import { Router } from "express"
|
||||||
|
import { createProxyMiddleware } from "http-proxy-middleware"
|
||||||
|
|
||||||
|
export const connectionsRoutes = Router()
|
||||||
|
|
||||||
|
const CONNECTIONSURL = "" // TODO: Meter al ENV
|
||||||
|
|
||||||
|
connectionsRoutes.post("/sim/activate", createProxyMiddleware({
|
||||||
|
target: CONNECTIONSURL + "/sim/activate",
|
||||||
|
changeOrigin: true,
|
||||||
|
// pathrewrite
|
||||||
|
//on proxy req
|
||||||
|
}))
|
||||||
|
|
||||||
|
connectionsRoutes.post("/sim/pause", createProxyMiddleware({
|
||||||
|
target: CONNECTIONSURL + "/sim/activate",
|
||||||
|
changeOrigin: true
|
||||||
|
}))
|
||||||
|
|
||||||
|
|
||||||
Reference in New Issue
Block a user