83 lines
1.9 KiB
TypeScript
83 lines
1.9 KiB
TypeScript
import { EventBus } from "../../shared/domain/EventBus.port";
|
|
import { SimEvents } from "../../shared/domain/SimEvents";
|
|
|
|
/**
|
|
* TODO:
|
|
* - Conexion con la BDD
|
|
* - Conexion con RabbitMQ
|
|
* - Pasar a clase cuando existan las conexiones
|
|
*/
|
|
export class SimUsecases {
|
|
private eventBus: EventBus
|
|
|
|
constructor(args: {
|
|
eventBus: EventBus
|
|
}
|
|
) {
|
|
this.eventBus = args.eventBus
|
|
}
|
|
|
|
/**
|
|
* Crea una nueva sim de la que no se tenia registro anteriormente
|
|
* Si ya existia se modifican los campos pero no se hace un cambio
|
|
* de estado.
|
|
*/
|
|
async save(args: { iccid: string, imei: string }) {
|
|
const activationEvent = <SimEvents.save>{
|
|
key: "sim.save",
|
|
payload: {
|
|
iccid: args.iccid,
|
|
imei: args.imei
|
|
}
|
|
}
|
|
|
|
return this.eventBus.publish([activationEvent])
|
|
}
|
|
|
|
async activation(args: { iccid: string, compañia: string }) {
|
|
|
|
const activationEvent = <SimEvents.general>{
|
|
key: `sim.${args.compañia}.activate`,
|
|
payload: {
|
|
iccid: args.iccid
|
|
}
|
|
}
|
|
console.log("[d] Activation ", activationEvent)
|
|
return this.eventBus.publish([activationEvent])
|
|
}
|
|
|
|
async cancelation(args: { iccid: string, compañia: string }) {
|
|
|
|
const activationEvent = <SimEvents.general>{
|
|
key: `sim.${args.compañia}.cancelation`,
|
|
payload: {
|
|
iccid: args.iccid
|
|
}
|
|
}
|
|
console.log("[d] Cancelation ", activationEvent)
|
|
return this.eventBus.publish([activationEvent])
|
|
}
|
|
|
|
async pause(args: { iccid: string }) {
|
|
const cancelationEvent = <SimEvents.pause>{
|
|
key: "sim.pause",
|
|
payload: {
|
|
iccid: args.iccid
|
|
}
|
|
}
|
|
|
|
return this.eventBus.publish([cancelationEvent])
|
|
}
|
|
async free(args: { iccid: string }) {
|
|
const cancelationEvent = <SimEvents.free>{
|
|
key: "sim.free",
|
|
payload: {
|
|
iccid: args.iccid
|
|
}
|
|
}
|
|
|
|
return this.eventBus.publish([cancelationEvent])
|
|
}
|
|
}
|
|
|