Base de los controladores y casos de uso
This commit is contained in:
@@ -28,15 +28,36 @@ export class SimUsecases {
|
||||
return this.eventBus.publish([activationEvent])
|
||||
}
|
||||
|
||||
cancelation(args: { iccid: string }) {
|
||||
throw new Error("Function not implemented.");
|
||||
async cancelation(args: { iccid: string }) {
|
||||
const cancelationEvent = <SimEvents.cancelation>{
|
||||
key: "sim.cancelation",
|
||||
payload: {
|
||||
iccid: args.iccid
|
||||
}
|
||||
}
|
||||
|
||||
return this.eventBus.publish([cancelationEvent])
|
||||
}
|
||||
|
||||
pause(args: { iccid: string }) {
|
||||
throw new Error("Function not implemented.");
|
||||
async pause(args: { iccid: string }) {
|
||||
const cancelationEvent = <SimEvents.pause>{
|
||||
key: "sim.pause",
|
||||
payload: {
|
||||
iccid: args.iccid
|
||||
}
|
||||
}
|
||||
|
||||
return this.eventBus.publish([cancelationEvent])
|
||||
}
|
||||
free(args: { iccid: string }) {
|
||||
throw new Error("Function not implemented.");
|
||||
async free(args: { iccid: string }) {
|
||||
const cancelationEvent = <SimEvents.free>{
|
||||
key: "sim.free",
|
||||
payload: {
|
||||
iccid: args.iccid
|
||||
}
|
||||
}
|
||||
|
||||
return this.eventBus.publish([cancelationEvent])
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -11,27 +11,147 @@ export class SimController {
|
||||
}
|
||||
|
||||
async activation(req: Request, res: Response) {
|
||||
const valido = this.validateBody(req.body, res)
|
||||
|
||||
if (valido == false) return; // Si no es valido ya se ha enviado el error
|
||||
|
||||
const { iccid } = req.body
|
||||
|
||||
if (iccid == undefined) {
|
||||
// TODO: excepcion con nombre se va a repetir
|
||||
res.status(400).json({
|
||||
msg: "iccid invalido"
|
||||
try {
|
||||
await this.simUseCases.activation({ iccid })
|
||||
} catch (err) {
|
||||
console.error("Error activando la sim ", req.body)
|
||||
res.status(500).json({
|
||||
errors: {
|
||||
msg: "Error general de activation"
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
const resp = await this.simUseCases.activation({ iccid })
|
||||
res.status(200).json({
|
||||
iccid: iccid,
|
||||
operation: "activation"
|
||||
})
|
||||
}
|
||||
|
||||
cancelation(req: Request, res: Response) {
|
||||
async cancelation(req: Request, res: Response) {
|
||||
const valido = this.validateBody(req.body, res)
|
||||
|
||||
if (valido == false) return; // Si no es valido ya se ha enviado el error
|
||||
|
||||
const { iccid } = req.body
|
||||
|
||||
try {
|
||||
await this.simUseCases.cancelation({ iccid })
|
||||
} catch (err) {
|
||||
console.error("Error cancelando la sim ", req.body)
|
||||
res.status(500).json({
|
||||
errors: {
|
||||
msg: "Error general de cancelacion"
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
res.status(200).json({
|
||||
iccid: iccid,
|
||||
operation: "cancelation"
|
||||
})
|
||||
}
|
||||
|
||||
pause(req: Request, res: Response) {
|
||||
async pause(req: Request, res: Response) {
|
||||
|
||||
const valido = this.validateBody(req.body, res)
|
||||
|
||||
if (valido == false) return; // Si no es valido ya se ha enviado el error
|
||||
|
||||
const { iccid } = req.body
|
||||
|
||||
try {
|
||||
await this.simUseCases.cancelation({ iccid })
|
||||
} catch (err) {
|
||||
console.error("Error pausando la sim ", req.body)
|
||||
res.status(500).json({
|
||||
errors: {
|
||||
msg: "Error pausando la sim"
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
res.status(200).json({
|
||||
iccid: iccid,
|
||||
operation: "cancelation"
|
||||
})
|
||||
}
|
||||
|
||||
free(req: Request, res: Response) {
|
||||
async free(req: Request, res: Response) {
|
||||
|
||||
const valido = this.validateBody(req.body, res)
|
||||
|
||||
if (valido == false) return; // Si no es valido ya se ha enviado el error
|
||||
|
||||
const { iccid } = req.body
|
||||
|
||||
try {
|
||||
await this.simUseCases.cancelation({ iccid })
|
||||
} catch (err) {
|
||||
console.error("Error liberando la sim ", req.body)
|
||||
res.status(500).json({
|
||||
errors: {
|
||||
msg: "Error general de liberacion"
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
res.status(200).json({
|
||||
iccid: iccid,
|
||||
operation: "liberacion"
|
||||
})
|
||||
}
|
||||
|
||||
async save(req: Request, res: Response) {
|
||||
|
||||
const valido = this.validateBody(req.body, res)
|
||||
|
||||
if (valido == false) return; // Si no es valido ya se ha enviado el error
|
||||
|
||||
const { iccid } = req.body
|
||||
|
||||
try {
|
||||
await this.simUseCases.cancelation({ iccid })
|
||||
} catch (err) {
|
||||
console.error("Error activando la sim ", req.body)
|
||||
res.status(500).json({
|
||||
errors: {
|
||||
msg: "Error general de activation"
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
res.status(200).json({
|
||||
iccid: iccid,
|
||||
operation: "cancelation"
|
||||
})
|
||||
}
|
||||
|
||||
private validateBody(body: any, res: Response) {
|
||||
const { iccid } = body
|
||||
let errors = {}
|
||||
let valid = true
|
||||
|
||||
if (iccid == undefined) {
|
||||
res.status(400)
|
||||
|
||||
errors = {
|
||||
...errors,
|
||||
iccid: "El iccid es undefined"
|
||||
}
|
||||
valid = false
|
||||
}
|
||||
|
||||
res.json({
|
||||
errors: errors
|
||||
})
|
||||
|
||||
return valid;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,20 +15,15 @@ const simController = new SimController({
|
||||
|
||||
simRoutes.get("/status", () => { })
|
||||
|
||||
simRoutes.post("/save", (req, res) => {
|
||||
|
||||
})
|
||||
simRoutes.post("/save", simController.save)
|
||||
|
||||
simRoutes.post("/activate", simController.activation)
|
||||
|
||||
simRoutes.post("/pause", (req, res) => {
|
||||
})
|
||||
simRoutes.post("/pause", simController.pause)
|
||||
|
||||
simRoutes.post("/cancel", (req, res) => {
|
||||
})
|
||||
simRoutes.post("/cancel", simController.cancelation)
|
||||
|
||||
// Proceso especifico de ALAI para liberar sims canceladas
|
||||
simRoutes.post("/free", (req, res) => {
|
||||
})
|
||||
simRoutes.post("/free", simController.free)
|
||||
|
||||
export { simRoutes }
|
||||
|
||||
Reference in New Issue
Block a user