87 lines
2.2 KiB
TypeScript
87 lines
2.2 KiB
TypeScript
|
import { HOST, Paging } from "./common.js";
|
||
|
|
||
|
export interface ProductosQuery {
|
||
|
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;
|
||
|
};
|
||
|
/**
|
||
|
* 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<ProductosResponse> {
|
||
|
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");
|
||
|
}
|
||
|
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;
|
||
|
}
|