Compare commits

..

6 commits

5 changed files with 79 additions and 5 deletions

View file

@ -11,6 +11,7 @@ import {
Producto,
Precio,
getPublications,
getPriceLists,
} from "../index.js";
// TODO: hacerlo input
@ -53,18 +54,22 @@ function objectToDom(object: any) {
}
async function showResponse(statusEl: Element | null, promise: Promise<any>) {
if (statusEl) clear(statusEl);
try {
const response = await promise;
if (statusEl) {
clear(statusEl);
statusEl.append("¡Funcionó!");
if (response) {
statusEl.append(" Respuesta:", objectToDom(response));
}
} else alert(`¡Funcionó!${response ? ` Respuesta: ${response}` : ""}`);
} catch (error) {
if (statusEl) statusEl.append("Hubo un error :(", objectToDom(error));
else alert(`Hubo un error: ${error}`);
if (statusEl) {
clear(statusEl);
statusEl.append("Hubo un error :(", objectToDom(error));
} else {
alert(`Hubo un error: ${error}`);
}
}
}
@ -94,6 +99,11 @@ setupForm("#price-by-customer", (event) =>
filter: (event.target! as any).filter.value,
})
);
setupForm("#price-list", (event) =>
getPriceLists(HOST, token(), {
filter: (event.target! as any).filter.value,
})
);
setupForm("#customers", () => getCustomers(HOST, token(), {}));
let customer: Customer | null = null;
@ -186,7 +196,7 @@ setupForm("#pedido", async () => {
})),
Customer: {
CustomerID: 1,
User: "ADMIN",
User: customer.BusinessName,
IVACategoryCode: customer.IvaCategoryCode,
Email: "api@axoft.com", // En prod: customer.Email, tenemos que usar esto porque el usuario de prueba no tiene Email
ProvinceCode: customer.ProvinceCode,

View file

@ -23,6 +23,12 @@
pre {
overflow-x: auto;
}
summary {
position: sticky;
top: 0px;
background: white;
}
</style>
<label for="token-input">Access token: </label>
@ -59,9 +65,15 @@
<p class="status"></p>
</form>
<form id="customers">
<form id="price-list">
<button>Conseguir listas de precios</button>
<input name="filter" type="text" placeholder="Filtro por ID (opcional)" />
<p class="status"></p>
</form>
<form id="customers">
<button>Conseguir clientes</button>
<p class="status"></p>
</form>
<section>

View file

@ -4,6 +4,7 @@ export * from "./dummy.js";
export * from "./product.js";
export * from "./price.js";
export * from "./priceByCustomer.js";
export * from "./priceList.js";
export * from "./customer.js";
export * from "./order.js";
export * from "./publications.js";

View file

@ -2,6 +2,9 @@ import { Paginacion, paginacionToSearchParams, Paging } from "./common.js";
export interface PriceQuery {
paginacion?: Paginacion;
/**
* Filtrar por PriceListNumber
*/
filter?: string;
SKUCode?: string;
}

48
priceList.ts Normal file
View file

@ -0,0 +1,48 @@
import { Paginacion, paginacionToSearchParams, Paging } from "./common.js";
export interface PriceListQuery {
paginacion?: Paginacion;
filter?: string;
}
export interface PriceList {
PriceListNumber: number;
Description: string;
CommonCurrency: boolean;
IvaIncluded: boolean;
InternalTaxIncluded: boolean;
ValidityDateSince: string;
ValidityDateUntil: string;
Disabled: boolean;
}
export interface PriceListResponse {
Paging: Paging;
Data: PriceList[];
}
export async function getPriceLists(
host: string,
token: string,
options: PriceListQuery
): Promise<PriceListResponse> {
let searchParams = new URLSearchParams();
paginacionToSearchParams(options.paginacion, searchParams);
if (options.filter) {
searchParams.set("filter", options.filter);
}
const res = await fetch(
`${host}/api/Aperture/PriceList?${searchParams.toString()}`,
{
headers: {
accesstoken: token,
},
}
);
const json = await res.json();
console.debug(json);
if (json.Message) {
throw new Error(`Tango: ${json.Message}`);
}
return json;
}