Compare commits
6 commits
5d79510780
...
cf868a92e9
Author | SHA1 | Date | |
---|---|---|---|
cf868a92e9 | |||
cb3c12541b | |||
f9c69c6812 | |||
220b094b8b | |||
b5ba132517 | |||
cc63099252 |
5 changed files with 79 additions and 5 deletions
18
demo/demo.ts
18
demo/demo.ts
|
@ -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,
|
||||
|
|
|
@ -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>
|
||||
|
|
1
index.ts
1
index.ts
|
@ -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";
|
||||
|
|
3
price.ts
3
price.ts
|
@ -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
48
priceList.ts
Normal 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;
|
||||
}
|
Loading…
Reference in a new issue