refactor catalog products API method

Signed-off-by: Loan Laux <loan@outgrow.io>
This commit is contained in:
Loan Laux
2021-07-06 18:43:36 +03:00
parent 36efe7e89d
commit aa65a9bad9
4 changed files with 26 additions and 4 deletions

View File

@@ -1,6 +1,6 @@
import catalogItemsQuery from '@framework/utils/queries/catalog-items-query'
import { normalizeProduct } from '@framework/utils'
import type { ProductsEndpoint } from '.'
import type { ProductsEndpoint } from './products'
const getCart: ProductsEndpoint['handlers']['getProducts'] = async ({
req,
@@ -15,9 +15,13 @@ const getCart: ProductsEndpoint['handlers']['getProducts'] = async ({
},
})
const products = catalogItems.map((item) => normalizeProduct(item))
const products = catalogItems?.edges?.map(({ node }) => normalizeProduct(node))
res.status(200).json({ data: products ?? null })
res.status(200).json({
data: {
products: products ?? null
}
})
}
export default getCart