UNPKG

vinmonopolet-ts

Version:

Extracts information on products, categories and stores from Vinmonopolet

23 lines (22 loc) 753 B
import FacetValue from "../models/FacetValue"; import getProducts from "./getProducts"; async function getProductsByStore(store, opts) { const storeFacet = new FacetValue({ query: { query: { value: `availableInStores:${store}` } }, }); let facets = [storeFacet]; if (opts?.facet) facets.push(opts?.facet); if (opts?.facets) { const safeFacets = opts?.facets.filter((facet) => facet !== undefined); facets = facets.concat(safeFacets); } const options = { limit: opts?.limit, facets: facets, page: opts?.page ?? 1, }; const allProducts = await getProducts(options); return { ...allProducts, store }; } export default getProductsByStore;