49 lines
1.1 KiB
TypeScript
49 lines
1.1 KiB
TypeScript
|
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;
|
||
|
}
|