diff --git a/demo/demo.ts b/demo/demo.ts index 862fa6a..2fa1b6f 100644 --- a/demo/demo.ts +++ b/demo/demo.ts @@ -4,6 +4,7 @@ import { getPrices, getPricesByCustomer, getCustomers, + getPublications, } from "../index.js"; const tokenInput = document.querySelector("#token-input")!; @@ -77,6 +78,7 @@ setupForm("#save-token", async () => { localStorage.token = token(); }); setupForm("#productos", () => getProductos(token(), {})); +setupForm("#publicaciones", () => getPublications(token(), {})); setupForm("#price", () => getPrices(token(), {})); setupForm("#price-by-customer", (event) => getPricesByCustomer(token(), { filter: (event.target! as any).filter.value }) diff --git a/demo/index.html b/demo/index.html index d6e8e26..cc77607 100644 --- a/demo/index.html +++ b/demo/index.html @@ -38,6 +38,11 @@

+
+ +

+
+

diff --git a/index.ts b/index.ts index 2bcca5b..9549531 100644 --- a/index.ts +++ b/index.ts @@ -5,3 +5,4 @@ export * from "./product.js"; export * from "./price.js"; export * from "./priceByCustomer.js"; export * from "./customer.js"; +export * from "./publications.js"; diff --git a/publications.ts b/publications.ts new file mode 100644 index 0000000..615086c --- /dev/null +++ b/publications.ts @@ -0,0 +1,58 @@ +import { + HOST, + Paginacion, + paginacionToSearchParams, + Paging, +} from "./common.js"; + +export interface PublicationsQuery { + paginacion?: Paginacion; + productCode?: string; + skuCode?: string; + variantCode?: string; +} + +export interface Publication { + ProductCode: string; + Description: string; + VariantCode?: string; + VariantDescription?: string; + SkuCode: string; +} + +export interface PublicationsResponse { + Paging: Paging; + Data: Publication[]; +} + +// https://github.com/TangoSoftware/ApiTiendas#art%C3%ADculos +export async function getPublications( + token: string, + options: PublicationsQuery +): Promise { + let searchParams = new URLSearchParams(); + paginacionToSearchParams(options.paginacion, searchParams); + if (options.skuCode) { + searchParams.set("skuCode", options.skuCode); + } + if (options.productCode) { + searchParams.set("productCode", options.productCode); + } + if (options.variantCode) { + searchParams.set("variantCode", options.variantCode); + } + const res = await fetch( + `${HOST}/api/Aperture/Publications?${searchParams.toString()}`, + { + headers: { + accesstoken: token, + }, + } + ); + const json = await res.json(); + console.debug(json); + if (json.Message) { + throw new Error(`Tango: ${json.Message}`); + } + return json; +}