import { HOST, Paginacion, paginacionToSearchParams, Paging, } from "./common.js"; export interface ProductosQuery { paginacion?: Paginacion; /** * Decide si solo traer los productos habilitados. */ onlyEnabled?: boolean; } export interface Producto { SKUCode: string; Description: string; AdditionalDescription: string; AlternativeCode: string; BarCode: string; Commission: number; Discount: number; MeasureUnitCode: string; SalesMeasureUnitCode: string; SalesEquivalence: number; MaximumStock: number; MinimumStock: number; RestockPoint: number; Observations: string; Kit: boolean; KitValidityDateSince?: string; KitValidityDateUntil?: string; UseScale: string; Scale1: string; Scale2: string; BaseArticle: string; ScaleValue1: string; ScaleValue2: string; DescriptionScale1: string; DescriptionScale2: string; DescriptionValueScale1: string; DescriptionValueScale2: string; Disabled: boolean; ProductComposition: { ComponentSKUCode: string; Quantity: number }[]; ProductComments: { Line: number; Text: string }[]; } export interface ProductosResponse { Paging: Paging; Data: Producto[]; } // https://github.com/TangoSoftware/ApiTiendas#art%C3%ADculos export async function getProductos( token: string, options: ProductosQuery ): Promise { let searchParams = new URLSearchParams(); paginacionToSearchParams(options.paginacion, searchParams); if ("onlyEnabled" in options) { searchParams.set("onlyEnabled", options.onlyEnabled ? "true" : "false"); } const res = await fetch( `${HOST}/api/Aperture/Product?${searchParams.toString()}`, { headers: { accesstoken: token, }, } ); const json: ProductosResponse = await res.json(); console.debug(json); return json; }