Ajuste para enrutar por compañia y actividad
This commit is contained in:
@@ -1,6 +1,15 @@
|
||||
import { DomainEvent } from "./DomainEvent";
|
||||
|
||||
export namespace SimEvents {
|
||||
export type general = DomainEvent & {
|
||||
key: string,
|
||||
payload: {
|
||||
iccid: string
|
||||
},
|
||||
options: {
|
||||
}
|
||||
}
|
||||
|
||||
export type activation = DomainEvent & {
|
||||
key: "sim.activation",
|
||||
payload: {
|
||||
|
||||
@@ -1,9 +0,0 @@
|
||||
import { RabbitMQEventBus } from "./RabbitMQEventBus";
|
||||
|
||||
export class RabbitMQConsumer {
|
||||
constructor(
|
||||
connection: RabbitMQEventBus
|
||||
) {
|
||||
|
||||
}
|
||||
}
|
||||
@@ -26,10 +26,10 @@ export async function startRMQClient() {
|
||||
|
||||
// Bindings especificos, deberia meterlos en la clase
|
||||
try {
|
||||
rabbitmqEventBus.channel?.assertQueue("sim.nos")
|
||||
await rabbitmqEventBus.channel?.assertQueue("sim.nos")
|
||||
} catch {
|
||||
console.log("[i] Cola de sims de nos creada")
|
||||
rabbitmqEventBus.channel?.bindQueue("sim.nos", "sim.exchange", "sim.nos.*")
|
||||
await rabbitmqEventBus.channel?.bindQueue("sim.nos", "sim.exchange", "sim.nos.*")
|
||||
}
|
||||
|
||||
return rabbitmqEventBus
|
||||
|
||||
@@ -8,6 +8,8 @@ export class SimController {
|
||||
simUseCases: SimUsecases
|
||||
}) {
|
||||
this.simUseCases = args.simUseCases
|
||||
|
||||
this.activation = this.activation.bind(this)
|
||||
}
|
||||
|
||||
async activation(req: Request, res: Response) {
|
||||
@@ -16,22 +18,23 @@ export class SimController {
|
||||
if (valido == false) return; // Si no es valido ya se ha enviado el error
|
||||
|
||||
const { iccid } = req.body
|
||||
const compañia = "nos" // esto deberia ser un servcio
|
||||
|
||||
try {
|
||||
await this.simUseCases.activation({ iccid })
|
||||
await this.simUseCases.activation({ iccid, compañia })
|
||||
} catch (err) {
|
||||
console.error("Error activando la sim ", req.body)
|
||||
res.status(500).json({
|
||||
errors: {
|
||||
msg: "Error general de activation"
|
||||
}
|
||||
})
|
||||
}).send()
|
||||
}
|
||||
|
||||
res.status(200).json({
|
||||
iccid: iccid,
|
||||
operation: "activation"
|
||||
})
|
||||
}).send()
|
||||
}
|
||||
|
||||
async cancelation(req: Request, res: Response) {
|
||||
@@ -148,9 +151,11 @@ export class SimController {
|
||||
valid = false
|
||||
}
|
||||
|
||||
res.json({
|
||||
errors: errors
|
||||
})
|
||||
if (valid == false) {
|
||||
res.json({
|
||||
errors: errors
|
||||
})
|
||||
}
|
||||
|
||||
return valid;
|
||||
}
|
||||
|
||||
@@ -34,14 +34,15 @@ export class SimUsecases {
|
||||
return this.eventBus.publish([activationEvent])
|
||||
}
|
||||
|
||||
async activation(args: { iccid: string }) {
|
||||
const activationEvent = <SimEvents.activation>{
|
||||
key: "sim.activation",
|
||||
async activation(args: { iccid: string, compañia: string }) {
|
||||
const activationEvent = <SimEvents.general>{
|
||||
key: "sim.nos.activate",
|
||||
payload: {
|
||||
iccid: args.iccid
|
||||
}
|
||||
}
|
||||
|
||||
console.log("publicando", activationEvent)
|
||||
return this.eventBus.publish([activationEvent])
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user