Files
sf-sim/packages/sim-entrada-eventos/aplication/Sim.usecases.ts

104 lines
2.5 KiB
TypeScript
Raw Normal View History

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
}
2026-01-14 17:30:55 +01:00
/**
* 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, compañia: string }) {
2026-01-14 17:30:55 +01:00
const activationEvent = <SimEvents.save>{
key: `sim.${args.compañia}.save`,
2026-01-14 17:30:55 +01:00
payload: {
iccid: args.iccid,
imei: args.imei
}
}
return this.eventBus.publish([activationEvent])
}
async activation(args: { iccid: string, compañia: string, offer: string }) {
2026-01-27 14:48:44 +01:00
const activationEvent = <SimEvents.activation>{
2026-01-26 15:04:17 +01:00
key: `sim.${args.compañia}.activate`,
payload: {
iccid: args.iccid,
offer: args.offer
}
}
2026-01-27 14:48:44 +01:00
console.log("[d] Activation ", activationEvent)
return this.eventBus.publish([activationEvent])
}
async preActivation(args: { iccid: string, compañia: string }) {
const preActivationEvent = <SimEvents.preActivation>{
key: `sim.${args.compañia}.preActivate`,
payload: {
iccid: args.iccid
}
}
console.log("[d] Pre - activation ", preActivationEvent)
return this.eventBus.publish([preActivationEvent])
}
/**
* Para objenious es terminate
*/
2026-01-30 10:42:48 +01:00
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])
}
// alias por si acaso
public terminate = this.cancelation;
/**
* alias de bloquear / suspender en objenious
*/
async pause(args: { iccid: string, compañia: string }) {
const cancelationEvent = <SimEvents.pause>{
key: `sim.${args.compañia}.pause`,
payload: {
iccid: args.iccid
}
}
return this.eventBus.publish([cancelationEvent])
}
async free(args: { iccid: string, compañia: string }) {
const cancelationEvent = <SimEvents.free>{
key: `sim.${args.compañia}.free`,
payload: {
iccid: args.iccid
}
}
return this.eventBus.publish([cancelationEvent])
}
}