46 lines
883 B
TypeScript
46 lines
883 B
TypeScript
|
import {
|
||
|
HOST,
|
||
|
Paginacion,
|
||
|
paginacionToSearchParams,
|
||
|
Paging,
|
||
|
} from "./common.js";
|
||
|
|
||
|
export interface PriceQuery {
|
||
|
paginacion?: Paginacion;
|
||
|
}
|
||
|
|
||
|
export interface Price {
|
||
|
PriceListNumber: number;
|
||
|
SKUCode: string;
|
||
|
Price: number;
|
||
|
ValidityDateSince: string;
|
||
|
ValidityDateUntil: string;
|
||
|
}
|
||
|
|
||
|
export interface PriceResponse {
|
||
|
Paging: Paging;
|
||
|
Data: Price[];
|
||
|
}
|
||
|
|
||
|
export async function getPrices(
|
||
|
token: string,
|
||
|
options: PriceQuery
|
||
|
): Promise<PriceResponse> {
|
||
|
let searchParams = new URLSearchParams();
|
||
|
paginacionToSearchParams(options.paginacion, searchParams);
|
||
|
const res = await fetch(
|
||
|
`${HOST}/api/Aperture/Price?${searchParams.toString()}`,
|
||
|
{
|
||
|
headers: {
|
||
|
accesstoken: token,
|
||
|
},
|
||
|
}
|
||
|
);
|
||
|
const json = await res.json();
|
||
|
console.debug(json);
|
||
|
if (json.Message) {
|
||
|
throw new Error(`Tango: ${json.Message}`);
|
||
|
}
|
||
|
return json;
|
||
|
}
|