refactor category and brand filtering logic

Signed-off-by: Loan Laux <loan@outgrow.io>
This commit is contained in:
Loan Laux
2021-07-07 19:16:45 +03:00
parent 2160264d60
commit c2c43b76aa
8 changed files with 42 additions and 29 deletions

View File

@@ -1,16 +1,30 @@
import catalogItemsQuery from '@framework/utils/queries/catalog-items-query'
import { normalizeProduct } from '@framework/utils'
import type { ProductsEndpoint } from './products'
import getSearchVariables from '../../utils/get-search-variables'
const getCart: ProductsEndpoint['handlers']['getProducts'] = async ({
req,
res,
config,
}) => {
const {
brandId,
categoryId,
search,
sort,
} = req.query
const {
data: { catalogItems },
} = await config.fetch(catalogItemsQuery, {
variables: {
...getSearchVariables({
brandId,
categoryId,
search,
sort,
}),
shopIds: [config.shopId],
},
})