Todas las acciones de lineas de objenious
This commit is contained in:
@@ -64,7 +64,7 @@ export class SimController {
|
||||
}
|
||||
}
|
||||
|
||||
public activateSim() {
|
||||
public activate() {
|
||||
return async (msg: ConsumeMessage) => {
|
||||
let msgData;
|
||||
try {
|
||||
@@ -73,26 +73,83 @@ export class SimController {
|
||||
throw new Error("Error consumiendo el mensaje no es valido" + String(e))
|
||||
}
|
||||
|
||||
if (msgData == undefined || msgData.payload == undefined) throw new Error("Mensaje invalido")
|
||||
const iccid = msgData.payload.iccid
|
||||
const offer = msgData.payload.offer
|
||||
|
||||
if (offer == undefined) throw new Error("Error activando la sim, no se ha especificado la oferta")
|
||||
|
||||
this.tryUseCase(msg, this.useCases.activate({
|
||||
dueDate: this.genDueDate(2 * 60).toISOString(),
|
||||
identifier: {
|
||||
identifierType: "ICCID",
|
||||
identifiers: [iccid]
|
||||
},
|
||||
offer: {
|
||||
code: offer,
|
||||
services: []
|
||||
}
|
||||
}))
|
||||
}
|
||||
}
|
||||
|
||||
public suspendSim() {
|
||||
public preActivate() {
|
||||
return async (msg: ConsumeMessage) => {
|
||||
let msgData;
|
||||
try {
|
||||
msgData = this.validateMsg(msg) as SimEvents.pause
|
||||
} catch (e) {
|
||||
throw new Error("Error consumiendo el mensaje no es valido" + String(e))
|
||||
throw new Error("Error de preactivacion consumiendo el mensaje no es valido" + String(e))
|
||||
}
|
||||
|
||||
if (msgData == undefined) {
|
||||
return Promise.reject("Mensaje invalido")
|
||||
}
|
||||
|
||||
const iccid = msgData.payload.iccid
|
||||
this.tryUseCase(msg, this.useCases.preActivate({
|
||||
dueDate: this.genDueDate(2 * 60).toISOString(),
|
||||
identifier: {
|
||||
identifierType: "ICCID",
|
||||
identifiers: [iccid]
|
||||
}
|
||||
}))
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public reActivate() {
|
||||
return async (msg: ConsumeMessage) => {
|
||||
let msgData;
|
||||
try {
|
||||
msgData = this.validateMsg(msg) as SimEvents.pause
|
||||
} catch (e) {
|
||||
throw new Error("Error de reactivacion consumiendo el mensaje no es valido" + String(e))
|
||||
}
|
||||
|
||||
if (msgData == undefined) {
|
||||
return Promise.reject("Mensaje invalido")
|
||||
}
|
||||
|
||||
const iccid = msgData.payload.iccid
|
||||
this.tryUseCase(msg, this.useCases.suspend({
|
||||
dueDate: this.genDueDate(2 * 60).toISOString(),
|
||||
identifier: {
|
||||
identifierType: "ICCID",
|
||||
identifiers: [iccid]
|
||||
}
|
||||
}))
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public suspend() {
|
||||
return async (msg: ConsumeMessage) => {
|
||||
let msgData;
|
||||
try {
|
||||
msgData = this.validateMsg(msg) as SimEvents.pause
|
||||
} catch (e) {
|
||||
throw new Error("Error de suspension consumiendo el mensaje no es valido" + String(e))
|
||||
}
|
||||
|
||||
if (msgData == undefined) {
|
||||
|
||||
@@ -12,8 +12,11 @@ export class SimRouter {
|
||||
|
||||
constructor(private readonly simController: SimController) {
|
||||
this.routes = new Map([
|
||||
["activate", this.simController.activateSim()],
|
||||
["pause", this.simController.pauseSim()],
|
||||
["activate", this.simController.activate()],
|
||||
["pause", this.simController.suspend()],
|
||||
["cancel", this.simController.terminate()], // terminate
|
||||
["reActivate", this.simController.reActivate()],
|
||||
["preActivate", this.simController.preActivate()]
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
import { ActivationData } from "#domain/DTOs/objeniousapi.js"
|
||||
import { ActionData, ActivationData } from "#domain/DTOs/objeniousapi.js"
|
||||
import { HttpClient } from "#shared/infrastructure/HTTPClient.js"
|
||||
import { AxiosError } from "axios"
|
||||
import { Result } from "#shared/domain/Result"
|
||||
|
||||
// TODO: Pasar a un archivo de DTOs
|
||||
// TODO:
|
||||
// - Pasar a un archivo de DTOs
|
||||
// - Mucha repeticion por funcion, deberia hacer una plantilla
|
||||
|
||||
|
||||
export class SimUseCases {
|
||||
@@ -21,6 +23,8 @@ export class SimUseCases {
|
||||
public activate(activationData: ActivationData): () => Promise<Result<string, boolean>> {
|
||||
const OPERATION_URL = "/actions/activateLine"
|
||||
return async () => {
|
||||
// TODO: validacion de campos
|
||||
|
||||
const req = this.httpClient.client.post(OPERATION_URL, {
|
||||
...activationData
|
||||
})
|
||||
@@ -52,7 +56,31 @@ export class SimUseCases {
|
||||
}
|
||||
}
|
||||
|
||||
public reactivate(pauseData: ActivationData): () => Promise<Result<string, boolean>> {
|
||||
public preActivate(pauseData: ActionData): () => Promise<Result<string, boolean>> {
|
||||
const OPERATION_URL = "/actions/preactivateLine"
|
||||
return async () => {
|
||||
const req = this.httpClient.client.post(OPERATION_URL, {
|
||||
...pauseData
|
||||
})
|
||||
|
||||
try {
|
||||
const e = await req
|
||||
console.log("Sim preactivada con exito", e.data)
|
||||
return <Result<string, boolean>>{
|
||||
error: undefined,
|
||||
data: true
|
||||
}
|
||||
} catch (error) {
|
||||
console.error("Error preactivacion", error)
|
||||
return <Result<string, boolean>>{
|
||||
error: "Error preactivando la sim" + pauseData.identifier,
|
||||
data: true
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public reActivate(pauseData: ActionData): () => Promise<Result<string, boolean>> {
|
||||
const OPERATION_URL = "/actions/reactivateLine"
|
||||
return async () => {
|
||||
const req = this.httpClient.client.post(OPERATION_URL, {
|
||||
@@ -61,13 +89,13 @@ export class SimUseCases {
|
||||
|
||||
try {
|
||||
const e = await req
|
||||
console.log("Sim pausada con exito", e.data)
|
||||
console.log("Sim reactivada con exito", e.data)
|
||||
return <Result<string, boolean>>{
|
||||
error: undefined,
|
||||
data: true
|
||||
}
|
||||
} catch (error) {
|
||||
console.error("Error pausa", error)
|
||||
console.error("Error reactivacion", error)
|
||||
return <Result<string, boolean>>{
|
||||
error: "Error reactivando la sim" + pauseData.identifier,
|
||||
data: true
|
||||
@@ -76,7 +104,7 @@ export class SimUseCases {
|
||||
}
|
||||
}
|
||||
|
||||
public suspend(suspendData: ActivationData): () => Promise<Result<string, boolean>> {
|
||||
public suspend(suspendData: ActionData): () => Promise<Result<string, boolean>> {
|
||||
const OPERATION_URL = "/actions/suspendLine"
|
||||
return async () => {
|
||||
const req = this.httpClient.client.post(OPERATION_URL, {
|
||||
@@ -85,7 +113,7 @@ export class SimUseCases {
|
||||
|
||||
try {
|
||||
const e = await req
|
||||
console.log("Sim pausada con exito", e.data)
|
||||
console.log("Sim pausada/suspendida con exito", e.data)
|
||||
return <Result<string, boolean>>{
|
||||
error: undefined,
|
||||
data: true
|
||||
@@ -100,16 +128,19 @@ export class SimUseCases {
|
||||
}
|
||||
}
|
||||
|
||||
public terminate(terminationData: ActivationData): () => Promise<Result<string, boolean>> {
|
||||
public terminate(terminationData: ActionData): () => Promise<Result<string, boolean>> {
|
||||
const OPERATION_URL = "/actions/terminateLine"
|
||||
return async () => {
|
||||
const req = this.httpClient.client.post(OPERATION_URL, {
|
||||
...terminationData
|
||||
})
|
||||
|
||||
// TODO: para cuando estemos listos.
|
||||
throw new Error("Peticion no reversible desactivada de momento")
|
||||
|
||||
try {
|
||||
const e = await req
|
||||
console.log("Sim pausada con exito", e.data)
|
||||
console.log("Sim cancelada con exito", e.data)
|
||||
return <Result<string, boolean>>{
|
||||
error: undefined,
|
||||
data: true
|
||||
|
||||
Reference in New Issue
Block a user