hyperpop.js/priceList.ts

49 lines
1.1 KiB
TypeScript
Raw Permalink Normal View History

2021-11-18 15:07:35 +00:00
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;
}