Router intermedio para las ops de objenious

This commit is contained in:
2026-01-28 17:21:30 +01:00
parent ca75f00e22
commit 4acc04fb51
9 changed files with 183 additions and 84 deletions

View File

@@ -0,0 +1,57 @@
import { EventBus } from "#shared/domain/EventBus.port";
import { ConsumeMessage } from "amqplib";
import { SimUseCases } from "./Sim.usecases";
export class SimController {
private eventBus: EventBus;
private useCases: SimUseCases
constructor(
eventBus: EventBus,
useCases: SimUseCases
) {
this.eventBus = eventBus
this.useCases = useCases
}
public async activateSim(msg: ConsumeMessage | null) {
return async () => {
if (!this.validateActivationMsg(msg)) {
throw new Error("Error consumiendo el mensaje no es valido")
}
const msgData = Buffer.from(JSON.parse(msg?.content.toString("utf-8") || "{}").data)
console.log("Mensaje procesado", String(msgData))
// Caso de uso de activaciones
await this.useCases.activate({
dueDate: new Date().toString(),
identifier: {
identifierType: "ICCID",
identifiers: ["1234"]
}
})()
// TODO: comprobar el resultado de la opreacion
this.eventBus.ack(msg!)
}
}
public async pauseSim(msg: ConsumeMessage | null) {
return async () => {
if (!this.validateActivationMsg(msg)) {
throw new Error("Error consumiendo el mensaje no es valido")
}
const msgData = Buffer.from(JSON.parse(msg?.content.toString("utf-8") || "{}").data)
console.log("Mensaje procesado", String(msgData))
}
}
/**
* TODO:
* - Loguear motivos de la no validacion
*/
private validateActivationMsg(msg: ConsumeMessage | null) {
if (msg == undefined) return false;
return true;
}
}