56 lines
1.2 KiB
TypeScript
56 lines
1.2 KiB
TypeScript
|
import { HOST, Paging } from "./common.js";
|
||
|
|
||
|
export interface PreciosQuery {
|
||
|
paginacion?: {
|
||
|
/**
|
||
|
* El número de la página. Empieza desde 1.
|
||
|
*/
|
||
|
number: number;
|
||
|
/**
|
||
|
* El tamaño de la página. Tiene un límite de 5000.
|
||
|
*/
|
||
|
size: number;
|
||
|
};
|
||
|
}
|
||
|
|
||
|
export interface Precio {
|
||
|
SKUCode: string;
|
||
|
CustomerCode: string;
|
||
|
Price: number;
|
||
|
PriceListNumber: number;
|
||
|
}
|
||
|
|
||
|
export interface PreciosResponse {
|
||
|
Paging: Paging;
|
||
|
Data: Precio[];
|
||
|
}
|
||
|
|
||
|
export async function getPricesByCustomer(
|
||
|
token: string,
|
||
|
options: PreciosQuery
|
||
|
): Promise<PreciosResponse> {
|
||
|
let searchParams = new URLSearchParams();
|
||
|
if (options.paginacion) {
|
||
|
searchParams.set("pageSize", options.paginacion.size.toString());
|
||
|
searchParams.set("pageNumber", options.paginacion.number.toString());
|
||
|
} else {
|
||
|
// El máximo, según lo que retorna en 'Paging'
|
||
|
searchParams.set("pageSize", "5000");
|
||
|
searchParams.set("pageNumber", "1");
|
||
|
}
|
||
|
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;
|
||
|
}
|