getPricesByCustomer: filter

This commit is contained in:
Cat /dev/Nulo 2021-10-12 19:57:24 -03:00
parent 9d49e1aa1e
commit c21e34cc07
3 changed files with 11 additions and 3 deletions

View file

@ -58,7 +58,7 @@ async function showResponse(statusEl: Element | null, promise: Promise<any>) {
} }
} }
function setupForm(selector: string, listener: () => Promise<any>) { function setupForm(selector: string, listener: (event: Event) => Promise<any>) {
const formEl = document.querySelector<HTMLFormElement>(selector); const formEl = document.querySelector<HTMLFormElement>(selector);
if (!formEl) throw new Error(`No existe el formulario ${selector}`); if (!formEl) throw new Error(`No existe el formulario ${selector}`);
const statusEl = formEl.querySelector<HTMLElement>(".status"); const statusEl = formEl.querySelector<HTMLElement>(".status");
@ -68,7 +68,7 @@ function setupForm(selector: string, listener: () => Promise<any>) {
); );
formEl.addEventListener("submit", async (event) => { formEl.addEventListener("submit", async (event) => {
event.preventDefault(); event.preventDefault();
showResponse(statusEl, listener()); showResponse(statusEl, listener(event));
}); });
} }
@ -78,5 +78,7 @@ setupForm("#save-token", async () => {
}); });
setupForm("#productos", () => getProductos(token(), {})); setupForm("#productos", () => getProductos(token(), {}));
setupForm("#price", () => getPrices(token(), {})); setupForm("#price", () => getPrices(token(), {}));
setupForm("#price-by-customer", () => getPricesByCustomer(token(), {})); setupForm("#price-by-customer", (event) =>
getPricesByCustomer(token(), { filter: (event.target! as any).filter.value })
);
setupForm("#customer", () => getCustomers(token(), {})); setupForm("#customer", () => getCustomers(token(), {}));

View file

@ -45,6 +45,7 @@
<form id="price-by-customer"> <form id="price-by-customer">
<button>Conseguir precios by customer</button> <button>Conseguir precios by customer</button>
<input name="filter" type="text" placeholder="Filtro por ID (opcional)" />
<p class="status"></p> <p class="status"></p>
</form> </form>

View file

@ -7,6 +7,8 @@ import {
export interface PriceByCustomerQuery { export interface PriceByCustomerQuery {
paginacion?: Paginacion; paginacion?: Paginacion;
/// Filtro por el código del cliente ("Code" en Customer.)
filter?: string;
} }
export interface Precio { export interface Precio {
@ -27,6 +29,9 @@ export async function getPricesByCustomer(
): Promise<PreciosResponse> { ): Promise<PreciosResponse> {
let searchParams = new URLSearchParams(); let searchParams = new URLSearchParams();
paginacionToSearchParams(options.paginacion, searchParams); paginacionToSearchParams(options.paginacion, searchParams);
if (options.filter) {
searchParams.set("filter", options.filter);
}
const res = await fetch( const res = await fetch(
`${HOST}/api/Aperture/PriceByCustomer?${searchParams.toString()}`, `${HOST}/api/Aperture/PriceByCustomer?${searchParams.toString()}`,
{ {