import { Result } from "sim-shared/domain/Result.js"; import { NosHttpClient } from "./NosHttpClient"; import { NosApi } from "#domain/NosAPI.js"; import axios, { AxiosError, AxiosResponse } from "axios"; export class NosRepository { constructor( private httpClient: NosHttpClient ) { } /** * E => Tipo de error * T => Tipo de dato para cod 200 * * TODO: * - Mejor gestion de los errores * - E no se aplica todavia por no hacer la transformacion del error */ private async manageNosRequest(promise: Promise>): Promise> { try { const res = await promise return { data: res.data } } catch (e) { if (axios.isAxiosError(e)) { const error = e as AxiosError return { error: error.code + " : " + JSON.stringify(error.response) } } else { return { error: JSON.stringify(e) } } } } public async getLineInfo(iccid: string): Promise> { const PATH = "/subscribers/" + iccid const req = this.httpClient.post(PATH) const resp = await this.manageNosRequest(req) if (resp.error != undefined) { return resp } else { return { data: resp.data.content } } } public async activateSim(iccid: string): Promise> { const PATH = '/provisioning' const PRODUCT_ID = 1330 // No se que es, preguntar a Ivan const data = { productSetId: PRODUCT_ID } const req = this.httpClient.post(PATH, data) const resp = await this.manageNosRequest(req) if (resp.error != undefined) { return resp } else { return { data: resp.data.content } } } /** * "A bar is a service provisioning action that results in a subscriber being blocked from accessing an operator's network. The bar remains in place until the operator is sent an unbar request." * Se entiende que un "bar" es una suspension temporal */ public async bar(iccid: string) { const PATH = `/subscribers/${iccid}/products` const data = { product: "BAR DN TOTAL", action: "enable" } const req = this.httpClient.post(PATH, data) const resp = await this.manageNosRequest(req) if (resp.error != undefined) { return resp } else { return { data: resp.data.content } } } public async unbar(iccid: string) { const PATH = `/subscribers/${iccid}/products` const data = { product: "BAR DN TOTAL", action: "disable" } const req = this.httpClient.post(PATH, data) const resp = await this.manageNosRequest(req) if (resp.error != undefined) { return resp } else { return { data: resp.data.content } } } }