hyperpop.js/priceByCustomer.ts

50 lines
1 KiB
TypeScript
Raw Normal View History

2021-10-12 22:21:09 +00:00
import {
HOST,
Paginacion,
paginacionToSearchParams,
Paging,
} from "./common.js";
2021-09-23 00:17:35 +00:00
2021-10-12 22:21:09 +00:00
export interface PriceByCustomerQuery {
paginacion?: Paginacion;
2021-10-12 22:57:24 +00:00
/// Filtro por el código del cliente ("Code" en Customer.)
filter?: string;
2021-09-23 00:17:35 +00:00
}
export interface Precio {
SKUCode: string;
CustomerCode: string;
Price: number;
PriceListNumber: number;
}
export interface PreciosResponse {
Paging: Paging;
Data: Precio[];
}
export async function getPricesByCustomer(
token: string,
2021-10-12 22:21:09 +00:00
options: PriceByCustomerQuery
2021-09-23 00:17:35 +00:00
): Promise<PreciosResponse> {
let searchParams = new URLSearchParams();
2021-10-12 22:21:09 +00:00
paginacionToSearchParams(options.paginacion, searchParams);
2021-10-12 22:57:24 +00:00
if (options.filter) {
searchParams.set("filter", options.filter);
}
2021-09-23 00:17:35 +00:00
const res = await fetch(
`${HOST}/api/Aperture/PriceByCustomer?${searchParams.toString()}`,
{
headers: {
accesstoken: token,
},
}
);
const json = await res.json();
console.debug(json);
if (json.Message) {
throw new Error(`Tango: ${json.Message}`);
}
return json;
}