ontroladores y rutas
This commit is contained in:
@@ -92,13 +92,8 @@ export class SimAlaiController {
|
||||
}
|
||||
}
|
||||
|
||||
public terminate() {
|
||||
return async (msg: ConsumeMessage) => {
|
||||
console.log("Evento termiante no soportado ", msg.fields)
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
public reActivate() {
|
||||
return async (msg: ConsumeMessage) => {
|
||||
console.log("Evento reActivate ", msg.fields)
|
||||
@@ -113,7 +108,23 @@ export class SimAlaiController {
|
||||
return res;
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
public terminate() {
|
||||
return async (msg: ConsumeMessage) => {
|
||||
console.log("Evento reActivate ", msg.fields)
|
||||
const data = this.validateMsg(msg) as SimEvents.reActivation
|
||||
const iccid = data.payload.iccid
|
||||
const correlation_id = data.headers?.message_id
|
||||
const res = await this.tryUseCase(msg, this.uscases.terminate({
|
||||
iccid: iccid,
|
||||
correlation_id: correlation_id
|
||||
}))
|
||||
|
||||
return res;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Select especificamente por REST para evitar pasar por las colas.
|
||||
|
||||
@@ -22,9 +22,9 @@ export class SimAlaiRouter {
|
||||
this.routes = new Map<string, FuncType>([
|
||||
["activate", this.simController.activate()],
|
||||
["pause", this.simController.suspend()],
|
||||
//["reactivate", this.simController.reActivate()],
|
||||
//["cancel", this.simController.terminate()],
|
||||
//["preActivate", this.simController.preActivate()]
|
||||
["reactivate", this.simController.reActivate()],
|
||||
["cancel", this.simController.terminate()],
|
||||
["preActivate", this.simController.activate()]
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
@@ -68,7 +68,7 @@ export class SimAlaiUsecases {
|
||||
args: T,
|
||||
correlation_id?: string | undefined
|
||||
) {
|
||||
return async () => {
|
||||
return async (): Promise<Result<string, R>> => {
|
||||
// Operacion pending -> running
|
||||
if (correlation_id != undefined)
|
||||
this.setRunning(correlation_id)
|
||||
@@ -154,6 +154,9 @@ export class SimAlaiUsecases {
|
||||
const subscriptionId = preactivatedSim.data!.subscription.id
|
||||
if (args.externalId) {
|
||||
const externalIdAdded = await this.alaiRepository.changeExternalId(subscriptionId, args.externalId)
|
||||
if (externalIdAdded.error != undefined) {
|
||||
return externalIdAdded
|
||||
}
|
||||
}
|
||||
|
||||
// En connections acaba buscando el numero.
|
||||
@@ -162,24 +165,54 @@ export class SimAlaiUsecases {
|
||||
}, inputargs, args.correlation_id)
|
||||
}
|
||||
|
||||
/**
|
||||
* WIP
|
||||
*
|
||||
*/
|
||||
public suspend(args: {
|
||||
iccid: string,
|
||||
correlation_id: string | undefined
|
||||
}) {
|
||||
return this.usecaseTemplate(async (args /*iccid*/) => {
|
||||
const order = await this.alaiRepository.createOrder()
|
||||
if (order.error != undefined) {
|
||||
// Falla el crearse un order (problema de servidor, token, etc)
|
||||
console.error(order.error)
|
||||
return order
|
||||
return this.usecaseTemplate(async (args) => {
|
||||
const subscription = await this.alaiRepository.getSimByICCID(args.iccid)
|
||||
if (subscription.error != undefined) {
|
||||
return subscription
|
||||
}
|
||||
const reserved = await this.alaiRepository.createReserve(order.data.id, args)
|
||||
return reserved
|
||||
}, args.iccid, args.correlation_id)
|
||||
|
||||
// TODO: Controlar que no se encuentre la subscription
|
||||
const suspension = this.alaiRepository.pauseSubscription(subscription.data!.id)
|
||||
return suspension
|
||||
}, args, args.correlation_id)
|
||||
}
|
||||
|
||||
|
||||
public reactivate(args: {
|
||||
iccid: string,
|
||||
correlation_id: string | undefined
|
||||
}) {
|
||||
return this.usecaseTemplate(async (args) => {
|
||||
const subscription = await this.alaiRepository.getSimByICCID(args.iccid)
|
||||
if (subscription.error != undefined) {
|
||||
return subscription
|
||||
}
|
||||
|
||||
// TODO: Controlar que no se encuentre la subscription
|
||||
const suspension = this.alaiRepository.unPauseSubscription(subscription.data!.id)
|
||||
return suspension
|
||||
}, args, args.correlation_id)
|
||||
}
|
||||
|
||||
|
||||
public terminate(args: {
|
||||
iccid: string,
|
||||
correlation_id: string | undefined
|
||||
}) {
|
||||
return this.usecaseTemplate(async (args) => {
|
||||
const subscription = await this.alaiRepository.getSimByICCID(args.iccid)
|
||||
if (subscription.error != undefined) {
|
||||
return subscription
|
||||
}
|
||||
|
||||
// TODO: Controlar que no se encuentre la subscription
|
||||
const suspension = this.alaiRepository.terminateSubscription(subscription.data!.id)
|
||||
return suspension
|
||||
}, args, args.correlation_id)
|
||||
}
|
||||
|
||||
public async selectOne(iccid: string) {
|
||||
|
||||
Reference in New Issue
Block a user