Funcionan todos los select, pendiente el general
This commit is contained in:
@@ -5,7 +5,7 @@ meta {
|
|||||||
}
|
}
|
||||||
|
|
||||||
get {
|
get {
|
||||||
url:
|
url: {{baseurl}}/portugal/select
|
||||||
body: none
|
body: none
|
||||||
auth: inherit
|
auth: inherit
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,13 +5,13 @@ meta {
|
|||||||
}
|
}
|
||||||
|
|
||||||
get {
|
get {
|
||||||
url: {{baseurl}}/sim/select?iccid=8935103196306448300
|
url: {{baseurl}}/sim/select?iccid=8934909001500561503
|
||||||
body: none
|
body: none
|
||||||
auth: inherit
|
auth: inherit
|
||||||
}
|
}
|
||||||
|
|
||||||
params:query {
|
params:query {
|
||||||
iccid: 8935103196306448300
|
iccid: 8934909001500561503
|
||||||
}
|
}
|
||||||
|
|
||||||
settings {
|
settings {
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import { AlaiRepository } from "#infrastructure/AlaiRepository.js";
|
import { AlaiRepository } from "#infrastructure/AlaiRepository.js";
|
||||||
import { JWTToken } from "sim-shared/domain/JWT.js";
|
import { JWTToken } from "sim-shared/domain/JWT.js";
|
||||||
import { JWTProvider } from "sim-shared/infrastructure/HTTPClient.js";
|
import { JWTProvider } from "sim-shared/infrastructure/HTTPClient.js";
|
||||||
|
import { httpsAgent } from "#config/httpsAgent.js";
|
||||||
|
|
||||||
export class AlaiTokenManager implements JWTProvider<{}> {
|
export class AlaiTokenManager implements JWTProvider<{}> {
|
||||||
|
|
||||||
@@ -11,7 +11,7 @@ export class AlaiTokenManager implements JWTProvider<{}> {
|
|||||||
private async getNewAuthToken() {
|
private async getNewAuthToken() {
|
||||||
// TODO: Si no funcionase hay que reprogramar los mensajes para ser
|
// TODO: Si no funcionase hay que reprogramar los mensajes para ser
|
||||||
// consumidos mas tarde.
|
// consumidos mas tarde.
|
||||||
const res = await AlaiRepository.login();
|
const res = await AlaiRepository.login(httpsAgent);
|
||||||
|
|
||||||
if (res.error != undefined) {
|
if (res.error != undefined) {
|
||||||
console.error("Error obteniendo el token de ALAI", res.error)
|
console.error("Error obteniendo el token de ALAI", res.error)
|
||||||
|
|||||||
@@ -5,13 +5,13 @@ import { httpsAgent } from "./httpsAgent.js"
|
|||||||
import { DebugTokenManager } from "#aplication/DebugTokenManager.js";
|
import { DebugTokenManager } from "#aplication/DebugTokenManager.js";
|
||||||
|
|
||||||
const tokenManager = new AlaiTokenManager()
|
const tokenManager = new AlaiTokenManager()
|
||||||
const debugTokenManagr = new DebugTokenManager()
|
//const debugTokenManagr = new DebugTokenManager()
|
||||||
console.error("USANDO DebugTokenManager! Eliminar en prod")
|
//console.error("USANDO DebugTokenManager! Eliminar en prod")
|
||||||
|
|
||||||
|
|
||||||
export const alaiHttp = new HttpClient({
|
export const alaiHttp = new HttpClient({
|
||||||
baseURL: env.ALAI_API_URL as string,
|
baseURL: env.ALAI_API_URL as string,
|
||||||
headers: {},
|
headers: {},
|
||||||
jwtManager: debugTokenManagr,
|
jwtManager: tokenManager,
|
||||||
httpsAgent: httpsAgent
|
httpsAgent: httpsAgent
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ import axios, { AxiosError, AxiosResponse } from "axios";
|
|||||||
import { Result } from "sim-shared/domain/Result.js";
|
import { Result } from "sim-shared/domain/Result.js";
|
||||||
import { env } from "#config/env/env.js";
|
import { env } from "#config/env/env.js";
|
||||||
import { HttpClient } from "sim-shared/infrastructure/HTTPClient.js";
|
import { HttpClient } from "sim-shared/infrastructure/HTTPClient.js";
|
||||||
|
import https from "https"
|
||||||
|
|
||||||
export class AlaiRepository {
|
export class AlaiRepository {
|
||||||
constructor(
|
constructor(
|
||||||
@@ -30,7 +31,7 @@ export class AlaiRepository {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static async login(): Promise<Result<string, AlaiAPI.LoginResponseDTO>> {
|
public static async login(httpsAgent: https.Agent): Promise<Result<string, AlaiAPI.LoginResponseDTO>> {
|
||||||
const alaiUrl = env.ALAI_API_URL
|
const alaiUrl = env.ALAI_API_URL
|
||||||
const endpoint = "/v1/auth/login"
|
const endpoint = "/v1/auth/login"
|
||||||
const fullUrl = alaiUrl + endpoint
|
const fullUrl = alaiUrl + endpoint
|
||||||
@@ -41,7 +42,7 @@ export class AlaiRepository {
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const loginRes = await axios.post<AlaiAPI.LoginResponseDTO>(fullUrl, data)
|
const loginRes = await axios.post<AlaiAPI.LoginResponseDTO>(fullUrl, data, { httpsAgent })
|
||||||
return {
|
return {
|
||||||
data: loginRes.data
|
data: loginRes.data
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -127,7 +127,7 @@ export class SimNosController {
|
|||||||
const validateBody = iccidValidator.validate(body);
|
const validateBody = iccidValidator.validate(body);
|
||||||
|
|
||||||
if (validateBody.error != undefined) {
|
if (validateBody.error != undefined) {
|
||||||
res.status(402).json(validateBody)
|
res.status(422).json(validateBody)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -219,15 +219,16 @@ export class SimController {
|
|||||||
*/
|
*/
|
||||||
public select() {
|
public select() {
|
||||||
return async (req: Request, res: Response) => {
|
return async (req: Request, res: Response) => {
|
||||||
|
console.log("SELECT: ", req.query)
|
||||||
const iccid = req.query.iccid as string
|
const iccid = req.query.iccid as string
|
||||||
try {
|
const validationRes = iccidValidator.validate({ iccid: iccid })
|
||||||
iccidValidator.validate({ iccid: iccid })
|
if (validationRes.error != undefined) {
|
||||||
} catch (e) {
|
|
||||||
res.status(422).json({
|
res.status(422).json({
|
||||||
errors: {
|
errors: {
|
||||||
msg: e
|
...validationRes.error
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const company = companyFromIccid(iccid)
|
const company = companyFromIccid(iccid)
|
||||||
@@ -239,9 +240,9 @@ export class SimController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const respSelect = await axios.get(url + endpoint)
|
const respSelect = await axios.get(url + endpoint, { params: req.query })
|
||||||
res.json(respSelect.data)
|
res.json(respSelect.data)
|
||||||
// TODO: 200
|
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
if (isAxiosError(err)) {
|
if (isAxiosError(err)) {
|
||||||
const axiosErr = err as AxiosError
|
const axiosErr = err as AxiosError
|
||||||
|
|||||||
@@ -39,6 +39,8 @@ app.use("/france", franceRoutes)
|
|||||||
// Rutas especificas de España (Alai)
|
// Rutas especificas de España (Alai)
|
||||||
app.use("/spain", spainRoutes)
|
app.use("/spain", spainRoutes)
|
||||||
|
|
||||||
|
//TODO: app.use("/portugal", portugalRoutes)
|
||||||
|
|
||||||
app.get("/health", (req, res) => {
|
app.get("/health", (req, res) => {
|
||||||
res.status(200).json({ status: "ok" })
|
res.status(200).json({ status: "ok" })
|
||||||
})
|
})
|
||||||
|
|||||||
14
packages/sim-shared/domain/CommonSim.ts
Normal file
14
packages/sim-shared/domain/CommonSim.ts
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
export type CommonSim = {
|
||||||
|
company: "NOS" | "OBJ" | "ALAI",
|
||||||
|
iccid: string,
|
||||||
|
msisdn: string,
|
||||||
|
tariff: string, // Depende de la compañia
|
||||||
|
billing_state: "AVAILABLE" | "PREACTIVATED" | "ACTIVATED" | "SUSPENDED" | "TERMINATED" | "UNKNOWN",
|
||||||
|
network_state: "AVAILABLE" | "PREACTIVATED" | "ACTIVATED" | "SUSPENDED" | "TERMINATED" | "UNKNOWN",
|
||||||
|
preactivation_date?: Date | null,
|
||||||
|
activation_date?: Date | null,
|
||||||
|
suspension_date?: Date | null,
|
||||||
|
termination_date?: Date | null,
|
||||||
|
imei: string,
|
||||||
|
raw: any
|
||||||
|
}
|
||||||
@@ -1,20 +0,0 @@
|
|||||||
import { User } from "./User.js"
|
|
||||||
|
|
||||||
export type SimCard = {
|
|
||||||
iccid: string,
|
|
||||||
imei: string,
|
|
||||||
|
|
||||||
/* Pedido de shopify */
|
|
||||||
orderdId?: string, // Pasar a tipo
|
|
||||||
|
|
||||||
/* Subscripcion de shopify */
|
|
||||||
subscriptionId?: string, // Pasar a tipo
|
|
||||||
|
|
||||||
user?: User
|
|
||||||
|
|
||||||
createdAt?: Date,
|
|
||||||
updatedAt?: Date,
|
|
||||||
|
|
||||||
codigoOrigen?: string,
|
|
||||||
}
|
|
||||||
|
|
||||||
@@ -12,7 +12,8 @@ export namespace SimEvents {
|
|||||||
key: `sim.${string}.activate`,
|
key: `sim.${string}.activate`,
|
||||||
payload: {
|
payload: {
|
||||||
iccid: string,
|
iccid: string,
|
||||||
offer?: string
|
offer?: string,
|
||||||
|
orderId?: string
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +0,0 @@
|
|||||||
export type User = {
|
|
||||||
userId: string,
|
|
||||||
userName?: string,
|
|
||||||
email?: string,
|
|
||||||
tlfn?: string,
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user