Preactivacion y activacion alai
This commit is contained in:
@@ -67,6 +67,22 @@ export class SimAlaiController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public activate() {
|
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) => {
|
return async (msg: ConsumeMessage) => {
|
||||||
console.log("[i] Evento activate ", msg.fields)
|
console.log("[i] Evento activate ", msg.fields)
|
||||||
const data = this.validateMsg(msg) as SimEvents.activation
|
const data = this.validateMsg(msg) as SimEvents.activation
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ export class SimAlaiRouter {
|
|||||||
["pause", this.simController.suspend()],
|
["pause", this.simController.suspend()],
|
||||||
["reactivate", this.simController.reActivate()],
|
["reactivate", this.simController.reActivate()],
|
||||||
["cancel", this.simController.terminate()],
|
["cancel", this.simController.terminate()],
|
||||||
["preActivate", this.simController.activate()]
|
["preActivate", this.simController.preactivate()]
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -11,6 +11,7 @@
|
|||||||
import { AlaiAPI } from "#domain/AlaiAPI.js";
|
import { AlaiAPI } from "#domain/AlaiAPI.js";
|
||||||
import { AlaiRepository } from "#infrastructure/AlaiRepository.js";
|
import { AlaiRepository } from "#infrastructure/AlaiRepository.js";
|
||||||
import { ConsumeMessage } from "amqplib";
|
import { ConsumeMessage } from "amqplib";
|
||||||
|
import { error } from "node:console";
|
||||||
import { ErrorOrderDTO, FinishOrderDTO, UpdateOrderDTO } from "sim-shared/domain/Order.js";
|
import { ErrorOrderDTO, FinishOrderDTO, UpdateOrderDTO } from "sim-shared/domain/Order.js";
|
||||||
import { Result } from "sim-shared/domain/Result.js";
|
import { Result } from "sim-shared/domain/Result.js";
|
||||||
import { HttpClient } from "sim-shared/infrastructure/HTTPClient.js";
|
import { HttpClient } from "sim-shared/infrastructure/HTTPClient.js";
|
||||||
@@ -108,17 +109,31 @@ export class SimAlaiUsecases {
|
|||||||
|
|
||||||
public activate(args: {
|
public activate(args: {
|
||||||
iccid: string,
|
iccid: string,
|
||||||
correlation_id: string | undefined
|
correlation_id: string | undefined,
|
||||||
}) {
|
}) {
|
||||||
return this.usecaseTemplate(async (iccid /*iccid*/) => {
|
return this.usecaseTemplate(async (iccid /*iccid*/) => {
|
||||||
const order = await this.alaiRepository.createOrder()
|
const sim = await this.alaiRepository.getSimByICCID(iccid)
|
||||||
if (order.error != undefined) {
|
if (sim.error != undefined) {
|
||||||
// Falla el crearse un order (problema de servidor, token, etc)
|
return sim
|
||||||
console.error(order.error)
|
|
||||||
return order
|
|
||||||
}
|
}
|
||||||
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)
|
}, args.iccid, args.correlation_id)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -135,6 +135,22 @@ export class AlaiRepository {
|
|||||||
return res
|
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) {
|
public async unPauseSubscription(subscriptionId: string) {
|
||||||
const endpoint = `/v1/subscription/${subscriptionId}`
|
const endpoint = `/v1/subscription/${subscriptionId}`
|
||||||
// En teoria ahora se usa ["action", "UNBLOCK"] pero no he probado
|
// En teoria ahora se usa ["action", "UNBLOCK"] pero no he probado
|
||||||
|
|||||||
Reference in New Issue
Block a user