2021-11-15 21:57:36 +00:00
|
|
|
import { Paginacion, paginacionToSearchParams, Paging } from "./common.js";
|
2021-10-12 22:29:57 +00:00
|
|
|
|
|
|
|
export interface PriceQuery {
|
|
|
|
paginacion?: Paginacion;
|
2021-11-18 15:07:14 +00:00
|
|
|
/**
|
|
|
|
* Filtrar por PriceListNumber
|
|
|
|
*/
|
2021-11-01 20:49:14 +00:00
|
|
|
filter?: string;
|
|
|
|
SKUCode?: string;
|
2021-10-12 22:29:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export interface Price {
|
|
|
|
PriceListNumber: number;
|
|
|
|
SKUCode: string;
|
|
|
|
Price: number;
|
|
|
|
ValidityDateSince: string;
|
|
|
|
ValidityDateUntil: string;
|
|
|
|
}
|
|
|
|
|
|
|
|
export interface PriceResponse {
|
|
|
|
Paging: Paging;
|
|
|
|
Data: Price[];
|
|
|
|
}
|
|
|
|
|
|
|
|
export async function getPrices(
|
2021-11-15 21:57:36 +00:00
|
|
|
host: string,
|
2022-11-01 17:21:52 +00:00
|
|
|
headers: HeadersInit,
|
2021-10-12 22:29:57 +00:00
|
|
|
options: PriceQuery
|
|
|
|
): Promise<PriceResponse> {
|
|
|
|
let searchParams = new URLSearchParams();
|
|
|
|
paginacionToSearchParams(options.paginacion, searchParams);
|
2021-11-01 20:49:14 +00:00
|
|
|
if (options.filter) {
|
|
|
|
searchParams.set("filter", options.filter);
|
|
|
|
}
|
|
|
|
if (options.SKUCode) {
|
|
|
|
searchParams.set("SKUCode", options.SKUCode);
|
|
|
|
}
|
2021-10-12 22:29:57 +00:00
|
|
|
const res = await fetch(
|
2021-11-15 21:57:36 +00:00
|
|
|
`${host}/api/Aperture/Price?${searchParams.toString()}`,
|
2022-11-01 17:21:52 +00:00
|
|
|
{ headers }
|
2021-10-12 22:29:57 +00:00
|
|
|
);
|
|
|
|
const json = await res.json();
|
|
|
|
console.debug(json);
|
|
|
|
if (json.Message) {
|
|
|
|
throw new Error(`Tango: ${json.Message}`);
|
|
|
|
}
|
|
|
|
return json;
|
|
|
|
}
|