74 lines
1.9 KiB
TypeScript
74 lines
1.9 KiB
TypeScript
import { Paginacion, paginacionToSearchParams, Paging } from "./common.js";
|
|
|
|
export interface ProductosQuery {
|
|
paginacion?: Paginacion;
|
|
/**
|
|
* Decide si solo traer los productos habilitados.
|
|
*/
|
|
onlyEnabled?: boolean;
|
|
filter?: string;
|
|
}
|
|
|
|
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(
|
|
host: string,
|
|
headers: HeadersInit,
|
|
options: ProductosQuery
|
|
): Promise<ProductosResponse> {
|
|
let searchParams = new URLSearchParams();
|
|
paginacionToSearchParams(options.paginacion, searchParams);
|
|
if ("onlyEnabled" in options) {
|
|
searchParams.set("onlyEnabled", options.onlyEnabled ? "true" : "false");
|
|
}
|
|
if (options.filter) {
|
|
searchParams.set("filter", options.filter);
|
|
}
|
|
const res = await fetch(
|
|
`${host}/api/Aperture/Product?${searchParams.toString()}`,
|
|
{ headers }
|
|
);
|
|
const json = await res.json();
|
|
console.debug(json);
|
|
if (json.Message) {
|
|
throw new Error(`Tango: ${json.Message}`);
|
|
}
|
|
return json;
|
|
}
|