59 lines
1.3 KiB
TypeScript
59 lines
1.3 KiB
TypeScript
import {
|
|
QueryCustomer,
|
|
queryCustomerToSearchParams,
|
|
Paginacion,
|
|
paginacionToSearchParams,
|
|
Paging,
|
|
} from "./common.js";
|
|
|
|
export interface PriceByCustomerQuery {
|
|
paginacion?: Paginacion;
|
|
/// Filtro por el código del cliente ("Code" en Customer.)
|
|
filter?: string;
|
|
SKUCode?: string;
|
|
customer?: QueryCustomer;
|
|
}
|
|
|
|
export interface Precio {
|
|
SKUCode: string;
|
|
CustomerCode: string;
|
|
Price: number;
|
|
PriceListNumber: number;
|
|
}
|
|
|
|
export interface PreciosResponse {
|
|
Paging: Paging;
|
|
Data: Precio[];
|
|
}
|
|
|
|
export async function getPricesByCustomer(
|
|
host: string,
|
|
token: string,
|
|
options: PriceByCustomerQuery
|
|
): Promise<PreciosResponse> {
|
|
let searchParams = new URLSearchParams();
|
|
paginacionToSearchParams(options.paginacion, searchParams);
|
|
if (options.filter) {
|
|
searchParams.set("filter", options.filter);
|
|
}
|
|
if (options.SKUCode) {
|
|
searchParams.set("SKUCode", options.SKUCode);
|
|
}
|
|
if (options.customer) {
|
|
queryCustomerToSearchParams(options.customer, searchParams);
|
|
}
|
|
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;
|
|
}
|