Base de los controladores y casos de uso
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user