Problema de cancel y mensajes unack
This commit is contained in:
@@ -6,10 +6,14 @@ meta {
|
||||
|
||||
post {
|
||||
url: {{baseurl}}/sim/cancel
|
||||
body: none
|
||||
body: formUrlEncoded
|
||||
auth: inherit
|
||||
}
|
||||
|
||||
body:form-urlencoded {
|
||||
iccid: 8933201124059176320
|
||||
}
|
||||
|
||||
settings {
|
||||
encodeUrl: true
|
||||
timeout: 0
|
||||
|
||||
@@ -6,10 +6,18 @@ meta {
|
||||
|
||||
post {
|
||||
url: {{baseurl}}/sim/preactivate
|
||||
body: none
|
||||
body: formUrlEncoded
|
||||
auth: inherit
|
||||
}
|
||||
|
||||
params:query {
|
||||
~iccid: 1234
|
||||
}
|
||||
|
||||
body:form-urlencoded {
|
||||
iccid: 1234
|
||||
}
|
||||
|
||||
settings {
|
||||
encodeUrl: true
|
||||
timeout: 0
|
||||
|
||||
@@ -52,7 +52,7 @@ export class RabbitMQEventBus implements EventBus {
|
||||
const routingKey = msg.fields.routingKey
|
||||
|
||||
if (numberRetry < this.maxRetry) {
|
||||
console.log("Dalaying")
|
||||
console.log("Delaying")
|
||||
await this.channel.publish("sim.ex.objenious.delayed", routingKey, msg.content, {
|
||||
headers: {
|
||||
...headers,
|
||||
|
||||
@@ -57,6 +57,7 @@ export class SimController {
|
||||
return result
|
||||
} else {
|
||||
console.error("Error general procesando el caso de uso", result.error)
|
||||
this.eventBus.nack(msg)
|
||||
}
|
||||
} catch (e) {
|
||||
console.error("Error general procesando el caso de uso")
|
||||
|
||||
@@ -6,11 +6,15 @@
|
||||
|
||||
import { ConsumeMessage } from "amqplib";
|
||||
import { SimController } from "./Sim.controller.js";
|
||||
import { EventBus } from "#shared/domain/EventBus.port.js";
|
||||
|
||||
export class SimRouter {
|
||||
private readonly routes: Map<string, (m: ConsumeMessage) => Promise<any>>;
|
||||
|
||||
constructor(private readonly simController: SimController) {
|
||||
constructor(
|
||||
private readonly simController: SimController,
|
||||
private readonly eventBus: EventBus
|
||||
) {
|
||||
this.routes = new Map([
|
||||
["activate", this.simController.activate()],
|
||||
["pause", this.simController.suspend()],
|
||||
@@ -22,6 +26,7 @@ export class SimRouter {
|
||||
|
||||
/**
|
||||
* Enruta el mensaje a la acción correspondiente basándose en la routing key
|
||||
* TODO: No estoy seguro que deba meter el nack aqui
|
||||
*/
|
||||
public route = async (msg: ConsumeMessage | null): Promise<void> => {
|
||||
if (!msg) {
|
||||
@@ -33,6 +38,7 @@ export class SimRouter {
|
||||
|
||||
if (!action) {
|
||||
console.error("[Router] La routing key no tiene una acción definida", msg.fields.routingKey);
|
||||
this.eventBus.nack(msg)
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -40,6 +46,7 @@ export class SimRouter {
|
||||
|
||||
if (!handler) {
|
||||
console.error(`[Router] La acción '${action}' no tiene un controlador asociado`);
|
||||
this.eventBus.nack(msg)
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -55,6 +62,7 @@ export class SimRouter {
|
||||
|
||||
} catch (error) {
|
||||
console.error(`[Router] Error al ejecutar la operación '${action}':`, error);
|
||||
this.eventBus.nack(msg)
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -49,7 +49,7 @@ export class SimUseCases {
|
||||
} catch (error) {
|
||||
console.error("[Sim.usecase] Error activando ", (error as AxiosError).response?.status)
|
||||
return {
|
||||
error: "Error general de la petiacion",
|
||||
error: "Error general de la peticion",
|
||||
data: undefined
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,7 +14,7 @@ async function startWorker() {
|
||||
httpClient: httpClient
|
||||
})
|
||||
)
|
||||
const simRouter = new SimRouter(simActivationController)
|
||||
const simRouter = new SimRouter(simActivationController, rmqClient)
|
||||
|
||||
// de momento solo una cola por simplificar
|
||||
rmqClient.consume("sim.objenious", simRouter.route)
|
||||
|
||||
@@ -24,101 +24,106 @@ export class SimController {
|
||||
this.activation = this.activation.bind(this)
|
||||
}
|
||||
|
||||
async preactivation(req: Request, res: Response) {
|
||||
const valido = this.validateBody(req.body, res)
|
||||
if (valido == false) return;
|
||||
public preactivation() {
|
||||
return async (req: Request, res: Response) => {
|
||||
const valido = this.validateBody(req.body, res)
|
||||
if (valido == false) return;
|
||||
|
||||
const { iccid } = req.body
|
||||
const compañia = this.compañiaFromIccid(iccid)
|
||||
const { iccid } = req.body
|
||||
const compañia = this.compañiaFromIccid(iccid)
|
||||
|
||||
if (compañia == undefined) {
|
||||
res.status(500).json({
|
||||
errors: {
|
||||
msg: "El iccid no pertenece a una compañia conocida"
|
||||
}
|
||||
})
|
||||
return;
|
||||
}
|
||||
if (compañia == undefined) {
|
||||
res.status(500).json({
|
||||
errors: {
|
||||
msg: "El iccid no pertenece a una compañia conocida"
|
||||
}
|
||||
})
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
try {
|
||||
await this.simUseCases.preActivation({ iccid, compañia })
|
||||
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;
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async activation(req: Request, res: Response) {
|
||||
const valido = this.validateBody(req.body, res)
|
||||
public activation() {
|
||||
return async (req: Request, res: Response) => {
|
||||
const valido = this.validateBody(req.body, res)
|
||||
|
||||
if (valido == false) return; // Si no es valido ya se ha enviado el error
|
||||
if (valido == false) return; // Si no es valido ya se ha enviado el error
|
||||
|
||||
const { iccid, offer } = req.body
|
||||
const { iccid, offer } = req.body
|
||||
|
||||
const compañia = this.compañiaFromIccid(iccid)
|
||||
const compañia = this.compañiaFromIccid(iccid)
|
||||
|
||||
if (compañia == undefined) {
|
||||
res.status(500).json({
|
||||
errors: {
|
||||
msg: "El iccid no pertenece a una compañia conocida"
|
||||
}
|
||||
})
|
||||
return;
|
||||
}
|
||||
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 })
|
||||
try {
|
||||
await this.simUseCases.activation({ iccid, compañia, offer })
|
||||
|
||||
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;
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async cancelation(req: Request, res: Response) {
|
||||
const valido = this.validateBody(req.body, res)
|
||||
public cancelation() {
|
||||
return async (req: Request, res: Response) => {
|
||||
const valido = this.validateBody(req.body, res)
|
||||
|
||||
if (valido == false) return; // Si no es valido ya se ha enviado el error
|
||||
if (valido == false) return; // Si no es valido ya se ha enviado el error
|
||||
|
||||
const { iccid } = req.body
|
||||
const compañia = this.compañiaFromIccid(iccid)
|
||||
const { iccid } = req.body
|
||||
const compañia = this.compañiaFromIccid(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"
|
||||
}
|
||||
})
|
||||
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"
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public pause() {
|
||||
@@ -147,56 +152,57 @@ export class SimController {
|
||||
}
|
||||
}
|
||||
|
||||
async free(req: Request, res: Response) {
|
||||
public free() {
|
||||
return async (req: Request, res: Response) => {
|
||||
const valido = this.validateBody(req.body, res)
|
||||
|
||||
const valido = this.validateBody(req.body, res)
|
||||
if (valido == false) return; // Si no es valido ya se ha enviado el error
|
||||
|
||||
if (valido == false) return; // Si no es valido ya se ha enviado el error
|
||||
const { iccid } = req.body
|
||||
const compañia = this.compañiaFromIccid(iccid)
|
||||
|
||||
const { iccid } = req.body
|
||||
const compañia = this.compañiaFromIccid(iccid)
|
||||
|
||||
try {
|
||||
await this.simUseCases.cancelation({ iccid, compañia })
|
||||
res.status(200).json({
|
||||
iccid: iccid,
|
||||
operation: "liberacion"
|
||||
})
|
||||
} catch (err) {
|
||||
console.error("Error liberando la sim ", req.body)
|
||||
res.status(500).json({
|
||||
errors: {
|
||||
msg: "Error general de liberacion"
|
||||
}
|
||||
})
|
||||
try {
|
||||
await this.simUseCases.cancelation({ iccid, compañia })
|
||||
res.status(200).json({
|
||||
iccid: iccid,
|
||||
operation: "liberacion"
|
||||
})
|
||||
} catch (err) {
|
||||
console.error("Error liberando la sim ", req.body)
|
||||
res.status(500).json({
|
||||
errors: {
|
||||
msg: "Error general de liberacion"
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
async save(req: Request, res: Response) {
|
||||
public save() {
|
||||
|
||||
const valido = this.validateBody(req.body, res)
|
||||
return async (req: Request, res: Response) => {
|
||||
const valido = this.validateBody(req.body, res)
|
||||
|
||||
if (valido == false) return; // Si no es valido ya se ha enviado el error
|
||||
if (valido == false) return; // Si no es valido ya se ha enviado el error
|
||||
|
||||
const { iccid } = req.body
|
||||
const compañia = this.compañiaFromIccid(iccid)
|
||||
const { iccid } = req.body
|
||||
const compañia = this.compañiaFromIccid(iccid)
|
||||
|
||||
try {
|
||||
await this.simUseCases.cancelation({ iccid, compañia })
|
||||
res.status(200).json({
|
||||
iccid: iccid,
|
||||
operation: "cancelation"
|
||||
})
|
||||
} catch (err) {
|
||||
console.error("Error activando la sim ", req.body)
|
||||
res.status(500).json({
|
||||
errors: {
|
||||
msg: "Error general de activation"
|
||||
}
|
||||
})
|
||||
try {
|
||||
await this.simUseCases.cancelation({ iccid, compañia })
|
||||
res.status(200).json({
|
||||
iccid: iccid,
|
||||
operation: "cancelation"
|
||||
})
|
||||
} catch (err) {
|
||||
console.error("Error activando la sim ", req.body)
|
||||
res.status(500).json({
|
||||
errors: {
|
||||
msg: "Error general de activation"
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private validateBody(body: any, res: Response) {
|
||||
|
||||
@@ -64,8 +64,8 @@ export class SimUsecases {
|
||||
*/
|
||||
async cancelation(args: { iccid: string, compañia: string }) {
|
||||
|
||||
const activationEvent = <SimEvents.general>{
|
||||
key: `sim.${args.compañia}.cancelation`,
|
||||
const activationEvent = <SimEvents.cancel>{
|
||||
key: `sim.${args.compañia}.cancel`,
|
||||
payload: {
|
||||
iccid: args.iccid
|
||||
}
|
||||
|
||||
@@ -15,17 +15,17 @@ const simController = new SimController({
|
||||
|
||||
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("/preActivate", simController.preactivation)
|
||||
simRoutes.post("/preActivate", simController.preactivation())
|
||||
|
||||
simRoutes.post("/pause", simController.pause())
|
||||
|
||||
simRoutes.post("/cancel", simController.cancelation)
|
||||
simRoutes.post("/cancel", simController.cancelation())
|
||||
|
||||
// Proceso especifico de ALAI para liberar sims canceladas
|
||||
simRoutes.post("/free", simController.free)
|
||||
simRoutes.post("/free", simController.free())
|
||||
|
||||
export { simRoutes }
|
||||
|
||||
Reference in New Issue
Block a user