Ajuste de preactivacion con externalID
This commit is contained in:
@@ -108,18 +108,64 @@ export class SimAlaiUsecases {
|
||||
iccid: string,
|
||||
correlation_id: string | undefined
|
||||
}) {
|
||||
return this.usecaseTemplate(async (args /*iccid*/) => {
|
||||
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 reserved = await this.alaiRepository.createReserve(order.data.id, args)
|
||||
const reserved = await this.alaiRepository.createReserve(order.data.id, iccid)
|
||||
return reserved
|
||||
}, args.iccid, args.correlation_id)
|
||||
}
|
||||
|
||||
public preactivate(args: {
|
||||
iccid: string,
|
||||
correlation_id: string | undefined,
|
||||
externalId: string | undefined // Por compatibilidad
|
||||
}) {
|
||||
const inputargs = {
|
||||
iccid: args.iccid,
|
||||
externalId: args.externalId
|
||||
}
|
||||
return this.usecaseTemplate(async (args) => {
|
||||
const order = await this.alaiRepository.createOrder()
|
||||
if (order.error != undefined) {
|
||||
return order
|
||||
}
|
||||
const orderId = order.data.id
|
||||
const reserve = await this.alaiRepository.createReserve(orderId, args.iccid)
|
||||
if (reserve.error != undefined) {
|
||||
return reserve
|
||||
}
|
||||
|
||||
const applyOrder = await this.alaiRepository.applyOrder(orderId)
|
||||
if (applyOrder.error != undefined) {
|
||||
return applyOrder
|
||||
}
|
||||
|
||||
const preactivatedSim = await this.alaiRepository.getSimByICCID(args.iccid)
|
||||
if (preactivatedSim.error != undefined) {
|
||||
return preactivatedSim
|
||||
}
|
||||
|
||||
// TODO: Controlar sim no encotrada (No deberia pasar)
|
||||
const subscriptionId = preactivatedSim.data!.subscription.id
|
||||
if (args.externalId) {
|
||||
const externalIdAdded = await this.alaiRepository.changeExternalId(subscriptionId, args.externalId)
|
||||
}
|
||||
|
||||
// En connections acaba buscando el numero.
|
||||
const subscription = await this.alaiRepository.getSubscriptionById(subscriptionId)
|
||||
return subscription
|
||||
}, inputargs, args.correlation_id)
|
||||
}
|
||||
|
||||
/**
|
||||
* WIP
|
||||
*
|
||||
*/
|
||||
public suspend(args: {
|
||||
iccid: string,
|
||||
correlation_id: string | undefined
|
||||
|
||||
@@ -55,6 +55,8 @@ export namespace AlaiAPI {
|
||||
location: string
|
||||
}
|
||||
|
||||
export type ApplyOrder = UpdateSubscriptionDTO
|
||||
|
||||
export type Subscription = {
|
||||
id: string,
|
||||
name: string,
|
||||
|
||||
@@ -82,7 +82,7 @@ export class AlaiRepository {
|
||||
const params = new URLSearchParams([
|
||||
["action", "APPLY"]
|
||||
])
|
||||
const promReq = this.httpClient.patch(endpoint, undefined, { params: params })
|
||||
const promReq = this.httpClient.patch<AlaiAPI.ApplyOrderDTO>(endpoint, undefined, { params: params })
|
||||
const res = await this.manageRequest(promReq)
|
||||
return res
|
||||
}
|
||||
@@ -127,7 +127,7 @@ export class AlaiRepository {
|
||||
const data = {
|
||||
status: "BLOCKEDCORE"
|
||||
}
|
||||
const promReq = this.httpClient.patch<AlaiAPI.UpdateSubscriptionDTO | undefined>(endpoint, data)
|
||||
const promReq = this.httpClient.patch<AlaiAPI.UpdateSubscriptionDTO | undefined>(endpoint, data, { params: params })
|
||||
const res = await this.manageRequest(promReq)
|
||||
return res
|
||||
}
|
||||
@@ -141,7 +141,7 @@ export class AlaiRepository {
|
||||
const data = {
|
||||
status: "ACTIVE"
|
||||
}
|
||||
const promReq = this.httpClient.patch<AlaiAPI.UpdateSubscriptionDTO | undefined>(endpoint, data)
|
||||
const promReq = this.httpClient.patch<AlaiAPI.UpdateSubscriptionDTO | undefined>(endpoint, data, { params: params })
|
||||
const res = await this.manageRequest(promReq)
|
||||
return res
|
||||
}
|
||||
@@ -152,7 +152,7 @@ export class AlaiRepository {
|
||||
const params = new URLSearchParams([
|
||||
["action", "TERMINATE"]
|
||||
])
|
||||
const promReq = this.httpClient.patch<AlaiAPI.UpdateSubscriptionDTO | undefined>(endpoint, undefined)
|
||||
const promReq = this.httpClient.patch<AlaiAPI.UpdateSubscriptionDTO | undefined>(endpoint, undefined, { params: params })
|
||||
const res = await this.manageRequest(promReq)
|
||||
return res
|
||||
}
|
||||
@@ -166,7 +166,14 @@ export class AlaiRepository {
|
||||
const data = {
|
||||
externalID: externalId
|
||||
}
|
||||
const promReq = this.httpClient.patch<AlaiAPI.UpdateSubscriptionDTO | undefined>(endpoint, data)
|
||||
const promReq = this.httpClient.patch<AlaiAPI.UpdateSubscriptionDTO | undefined>(endpoint, data, { params: params })
|
||||
const res = await this.manageRequest(promReq)
|
||||
return res
|
||||
}
|
||||
|
||||
public async getSubscriptionById(subscriptionId: string) {
|
||||
const endpoint = `/v1/subscription/${subscriptionId}`
|
||||
const promReq = this.httpClient.patch<AlaiAPI.Subscription | undefined>(endpoint)
|
||||
const res = await this.manageRequest(promReq)
|
||||
return res
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user