getPricesByCustomer: filter
This commit is contained in:
parent
9d49e1aa1e
commit
c21e34cc07
3 changed files with 11 additions and 3 deletions
|
@ -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);
|
||||
if (!formEl) throw new Error(`No existe el formulario ${selector}`);
|
||||
const statusEl = formEl.querySelector<HTMLElement>(".status");
|
||||
|
@ -68,7 +68,7 @@ function setupForm(selector: string, listener: () => Promise<any>) {
|
|||
);
|
||||
formEl.addEventListener("submit", async (event) => {
|
||||
event.preventDefault();
|
||||
showResponse(statusEl, listener());
|
||||
showResponse(statusEl, listener(event));
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -78,5 +78,7 @@ setupForm("#save-token", async () => {
|
|||
});
|
||||
setupForm("#productos", () => getProductos(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(), {}));
|
||||
|
|
|
@ -45,6 +45,7 @@
|
|||
|
||||
<form id="price-by-customer">
|
||||
<button>Conseguir precios by customer</button>
|
||||
<input name="filter" type="text" placeholder="Filtro por ID (opcional)" />
|
||||
<p class="status"></p>
|
||||
</form>
|
||||
|
||||
|
|
|
@ -7,6 +7,8 @@ import {
|
|||
|
||||
export interface PriceByCustomerQuery {
|
||||
paginacion?: Paginacion;
|
||||
/// Filtro por el código del cliente ("Code" en Customer.)
|
||||
filter?: string;
|
||||
}
|
||||
|
||||
export interface Precio {
|
||||
|
@ -27,6 +29,9 @@ export async function getPricesByCustomer(
|
|||
): Promise<PreciosResponse> {
|
||||
let searchParams = new URLSearchParams();
|
||||
paginacionToSearchParams(options.paginacion, searchParams);
|
||||
if (options.filter) {
|
||||
searchParams.set("filter", options.filter);
|
||||
}
|
||||
const res = await fetch(
|
||||
`${HOST}/api/Aperture/PriceByCustomer?${searchParams.toString()}`,
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue