Hexagonal, mejora del cliente RMQ y tipos de eventos
This commit is contained in:
42
packages/sim-entrada-eventos/aplication/Sim.usecases.ts
Normal file
42
packages/sim-entrada-eventos/aplication/Sim.usecases.ts
Normal file
@@ -0,0 +1,42 @@
|
||||
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
|
||||
}
|
||||
|
||||
async activation(args: { iccid: string }) {
|
||||
const activationEvent = <SimEvents.activation>{
|
||||
key: "sim.activation",
|
||||
payload: {
|
||||
iccid: args.iccid
|
||||
}
|
||||
}
|
||||
|
||||
return this.eventBus.publish([activationEvent])
|
||||
}
|
||||
|
||||
cancelation(args: { iccid: string }) {
|
||||
throw new Error("Function not implemented.");
|
||||
}
|
||||
|
||||
pause(args: { iccid: string }) {
|
||||
throw new Error("Function not implemented.");
|
||||
}
|
||||
free(args: { iccid: string }) {
|
||||
throw new Error("Function not implemented.");
|
||||
}
|
||||
}
|
||||
|
||||
37
packages/sim-entrada-eventos/aplication/SimController.ts
Normal file
37
packages/sim-entrada-eventos/aplication/SimController.ts
Normal file
@@ -0,0 +1,37 @@
|
||||
import { Request, Response } from "express"
|
||||
import { SimUsecases } from "aplication/Sim.usecases"
|
||||
|
||||
export class SimController {
|
||||
private simUseCases: SimUsecases
|
||||
|
||||
constructor(args: {
|
||||
simUseCases: SimUsecases
|
||||
}) {
|
||||
this.simUseCases = args.simUseCases
|
||||
}
|
||||
|
||||
async activation(req: Request, res: Response) {
|
||||
const { iccid } = req.body
|
||||
|
||||
if (iccid == undefined) {
|
||||
// TODO: excepcion con nombre se va a repetir
|
||||
res.status(400).json({
|
||||
msg: "iccid invalido"
|
||||
})
|
||||
}
|
||||
|
||||
const resp = await this.simUseCases.activation({ iccid })
|
||||
}
|
||||
|
||||
cancelation(req: Request, res: Response) {
|
||||
|
||||
}
|
||||
|
||||
pause(req: Request, res: Response) {
|
||||
|
||||
}
|
||||
|
||||
free(req: Request, res: Response) {
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user