diff --git a/demo/demo.ts b/demo/demo.ts index ea4800b..4cfc3c3 100644 --- a/demo/demo.ts +++ b/demo/demo.ts @@ -11,6 +11,7 @@ import { Producto, Precio, getPublications, + getPriceLists, } from "../index.js"; // TODO: hacerlo input @@ -94,6 +95,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; diff --git a/demo/index.html b/demo/index.html index dc016c2..df7168b 100644 --- a/demo/index.html +++ b/demo/index.html @@ -59,6 +59,12 @@

+
+ + +

+
+

diff --git a/index.ts b/index.ts index a995a97..869ed60 100644 --- a/index.ts +++ b/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"; diff --git a/priceList.ts b/priceList.ts new file mode 100644 index 0000000..4dedb9b --- /dev/null +++ b/priceList.ts @@ -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 { + 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; +}