Preactivacion y activacion alai
This commit is contained in:
@@ -67,6 +67,22 @@ export class SimAlaiController {
|
||||
}
|
||||
|
||||
public activate() {
|
||||
return async (msg: ConsumeMessage) => {
|
||||
console.log("[i] Evento activate ", msg.fields)
|
||||
const data = this.validateMsg(msg) as SimEvents.activation
|
||||
const iccid = data.payload.iccid
|
||||
const correlation_id = data.headers?.message_id
|
||||
const externalId = data.payload.orderId
|
||||
|
||||
const res = await this.tryUseCase(msg, this.uscases.activate({
|
||||
iccid: iccid,
|
||||
correlation_id: correlation_id,
|
||||
}))
|
||||
return res;
|
||||
}
|
||||
}
|
||||
|
||||
public preactivate() {
|
||||
return async (msg: ConsumeMessage) => {
|
||||
console.log("[i] Evento activate ", msg.fields)
|
||||
const data = this.validateMsg(msg) as SimEvents.activation
|
||||
|
||||
@@ -24,7 +24,7 @@ export class SimAlaiRouter {
|
||||
["pause", this.simController.suspend()],
|
||||
["reactivate", this.simController.reActivate()],
|
||||
["cancel", this.simController.terminate()],
|
||||
["preActivate", this.simController.activate()]
|
||||
["preActivate", this.simController.preactivate()]
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
import { AlaiAPI } from "#domain/AlaiAPI.js";
|
||||
import { AlaiRepository } from "#infrastructure/AlaiRepository.js";
|
||||
import { ConsumeMessage } from "amqplib";
|
||||
import { error } from "node:console";
|
||||
import { ErrorOrderDTO, FinishOrderDTO, UpdateOrderDTO } from "sim-shared/domain/Order.js";
|
||||
import { Result } from "sim-shared/domain/Result.js";
|
||||
import { HttpClient } from "sim-shared/infrastructure/HTTPClient.js";
|
||||
@@ -108,17 +109,31 @@ export class SimAlaiUsecases {
|
||||
|
||||
public activate(args: {
|
||||
iccid: string,
|
||||
correlation_id: string | undefined
|
||||
correlation_id: string | undefined,
|
||||
}) {
|
||||
return this.usecaseTemplate(async (iccid /*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
|
||||
const sim = await this.alaiRepository.getSimByICCID(iccid)
|
||||
if (sim.error != undefined) {
|
||||
return sim
|
||||
}
|
||||
const reserved = await this.alaiRepository.createReserve(order.data.id, iccid)
|
||||
return reserved
|
||||
|
||||
if (sim.data == undefined) {
|
||||
return {
|
||||
error: `La sim ${iccid} no se ha encontrado`
|
||||
}
|
||||
}
|
||||
|
||||
const subscriptionId = sim.data.subscription.id
|
||||
|
||||
if (subscriptionId == undefined) {
|
||||
return {
|
||||
error: `La sim ${iccid} no tiene un id de subscripción`
|
||||
}
|
||||
}
|
||||
|
||||
const activationRes = await this.alaiRepository.activateSubscription(subscriptionId)
|
||||
return activationRes
|
||||
|
||||
}, args.iccid, args.correlation_id)
|
||||
}
|
||||
|
||||
|
||||
@@ -135,6 +135,22 @@ export class AlaiRepository {
|
||||
return res
|
||||
}
|
||||
|
||||
public async activateSubscription(subscriptionId: string) {
|
||||
const endpoint = `/v1/subscription/${subscriptionId}`
|
||||
// En teoria ahora se usa ["action", "UNBLOCK"] pero no he probado
|
||||
const params = new URLSearchParams([
|
||||
["action", "CHANGE_STATUS"]
|
||||
])
|
||||
|
||||
const data = {
|
||||
"status": "ACTIVE"
|
||||
}
|
||||
|
||||
const promReq = this.httpClient.patch<AlaiAPI.UpdateSubscriptionDTO | undefined>(endpoint, data, { params: params })
|
||||
const res = await this.manageRequest(promReq)
|
||||
return res
|
||||
}
|
||||
|
||||
public async unPauseSubscription(subscriptionId: string) {
|
||||
const endpoint = `/v1/subscription/${subscriptionId}`
|
||||
// En teoria ahora se usa ["action", "UNBLOCK"] pero no he probado
|
||||
|
||||
Reference in New Issue
Block a user