52 lines
1.2 KiB
TypeScript
52 lines
1.2 KiB
TypeScript
|
import { Paginacion, paginacionToSearchParams, Paging } from "./common.js";
|
||
|
|
||
|
export interface StockQuery {
|
||
|
paginacion?: Paginacion;
|
||
|
warehouseCode?: string;
|
||
|
filter?: string;
|
||
|
}
|
||
|
|
||
|
export interface Stock {
|
||
|
StoreNumber: number;
|
||
|
WarehouseCode: string;
|
||
|
SKUCode: string;
|
||
|
Quantity: number;
|
||
|
EngagedQuantity: number;
|
||
|
PendingQuantity: number;
|
||
|
}
|
||
|
|
||
|
export interface StockResponse {
|
||
|
Paging: Paging;
|
||
|
Data: Stock[];
|
||
|
}
|
||
|
|
||
|
// https://github.com/TangoSoftware/ApiTiendas#saldos-de-stock
|
||
|
export async function getStocks(
|
||
|
host: string,
|
||
|
token: string,
|
||
|
options: StockQuery
|
||
|
): Promise<StockResponse> {
|
||
|
let searchParams = new URLSearchParams();
|
||
|
paginacionToSearchParams(options.paginacion, searchParams);
|
||
|
if (options.filter) {
|
||
|
searchParams.set("filter", options.filter);
|
||
|
}
|
||
|
if (options.warehouseCode) {
|
||
|
searchParams.set("warehouseCode", options.warehouseCode);
|
||
|
}
|
||
|
const res = await fetch(
|
||
|
`${host}/api/Aperture/Stock?${searchParams.toString()}`,
|
||
|
{
|
||
|
headers: {
|
||
|
accesstoken: token,
|
||
|
},
|
||
|
}
|
||
|
);
|
||
|
const json = await res.json();
|
||
|
console.debug(json);
|
||
|
if (json.Message) {
|
||
|
throw new Error(`Tango: ${json.Message}`);
|
||
|
}
|
||
|
return json;
|
||
|
}
|