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, headers: HeadersInit, options: StockQuery ): Promise { 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 } ); const json = await res.json(); console.debug(json); if (json.Message) { throw new Error(`Tango: ${json.Message}`); } return json; }