Files
sf-sim/packages/sim-consumidor-objenious/aplication/Sim.controller.ts

58 lines
1.6 KiB
TypeScript
Raw Normal View History

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;
}
}