hyperpop.js/product.ts

76 lines
1.8 KiB
TypeScript
Raw Normal View History

2021-10-12 22:21:09 +00:00
import {
HOST,
Paginacion,
paginacionToSearchParams,
Paging,
} from "./common.js";
2021-09-23 00:17:35 +00:00
export interface ProductosQuery {
2021-10-12 22:21:09 +00:00
paginacion?: Paginacion;
2021-09-23 00:17:35 +00:00
/**
* 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();
2021-10-12 22:21:09 +00:00
paginacionToSearchParams(options.paginacion, searchParams);
2021-09-23 00:17:35 +00:00
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;
}