PriceList

This commit is contained in:
Cat /dev/Nulo 2021-11-18 12:07:35 -03:00
parent b5ba132517
commit 220b094b8b
4 changed files with 61 additions and 0 deletions

View file

@ -11,6 +11,7 @@ import {
Producto, Producto,
Precio, Precio,
getPublications, getPublications,
getPriceLists,
} from "../index.js"; } from "../index.js";
// TODO: hacerlo input // TODO: hacerlo input
@ -94,6 +95,11 @@ setupForm("#price-by-customer", (event) =>
filter: (event.target! as any).filter.value, 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(), {})); setupForm("#customers", () => getCustomers(HOST, token(), {}));
let customer: Customer | null = null; let customer: Customer | null = null;

View file

@ -59,6 +59,12 @@
<p class="status"></p> <p class="status"></p>
</form> </form>
<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"> <form id="customers">
<p class="status"></p> <p class="status"></p>
<button>Conseguir clientes</button> <button>Conseguir clientes</button>

View file

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

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;
}