mirror of
https://github.com/vercel/commerce.git
synced 2025-05-18 15:36:58 +00:00
refactor catalog products API method
Signed-off-by: Loan Laux <loan@outgrow.io>
This commit is contained in:
parent
36efe7e89d
commit
aa65a9bad9
@ -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
|
@ -1,4 +1,4 @@
|
||||
import productsApi from '@framework/api/endpoints/catalog/get-products'
|
||||
import productsApi from '@framework/api/endpoints/catalog/products'
|
||||
import commerce from '@lib/api/commerce'
|
||||
|
||||
export default productsApi(commerce)
|
||||
|
18
yarn.lock
18
yarn.lock
@ -1140,6 +1140,11 @@
|
||||
resolved "https://registry.yarnpkg.com/@types/scheduler/-/scheduler-0.16.1.tgz#18845205e86ff0038517aab7a18a62a6b9f71275"
|
||||
integrity sha512-EaCxbanVeyxDRTQBkdLb3Bvl/HK7PBK6UJjsSixB0iHKoWxE5uu2Q/DgtpOhPIojN0Zl1whvOd7PoHs2P0s5eA==
|
||||
|
||||
"@types/uuid@8.3.1":
|
||||
version "8.3.1"
|
||||
resolved "https://registry.yarnpkg.com/@types/uuid/-/uuid-8.3.1.tgz#1a32969cf8f0364b3d8c8af9cc3555b7805df14f"
|
||||
integrity sha512-Y2mHTRAbqfFkpjldbkHGY8JIzRN6XqYRliG8/24FcHm2D2PwW24fl5xMRTVGdrb7iMrwCaIEbLWerGIkXuFWVg==
|
||||
|
||||
"@types/websocket@1.0.2":
|
||||
version "1.0.2"
|
||||
resolved "https://registry.yarnpkg.com/@types/websocket/-/websocket-1.0.2.tgz#d2855c6a312b7da73ed16ba6781815bf30c6187a"
|
||||
@ -6044,6 +6049,19 @@ util@^0.12.0:
|
||||
safe-buffer "^5.1.2"
|
||||
which-typed-array "^1.1.2"
|
||||
|
||||
uuid@8.3.2:
|
||||
version "8.3.2"
|
||||
resolved "https://registry.yarnpkg.com/uuid/-/uuid-8.3.2.tgz#80d5b5ced271bb9af6c445f21a1a04c606cefbe2"
|
||||
integrity sha512-+NYs2QeMWy+GWFOEm9xnn6HCDp0l7QBD7ml8zLUmJ+93Q5NF0NocErnwkTkXVFNiX3/fpC6afS8Dhb/gz7R7eg==
|
||||
|
||||
uuidv4@^6.2.10:
|
||||
version "6.2.11"
|
||||
resolved "https://registry.yarnpkg.com/uuidv4/-/uuidv4-6.2.11.tgz#34d5a03324eb38296b87ae523a64233b5286cc27"
|
||||
integrity sha512-OTS4waH9KplrXNADKo+Q1kT9AHWr8DaC0S5F54RQzEwcUaEzBEWQQlJyDUw/u1bkRhJyqkqhLD4M4lbFbV+89g==
|
||||
dependencies:
|
||||
"@types/uuid" "8.3.1"
|
||||
uuid "8.3.2"
|
||||
|
||||
valid-url@1.0.9, valid-url@^1.0.9:
|
||||
version "1.0.9"
|
||||
resolved "https://registry.yarnpkg.com/valid-url/-/valid-url-1.0.9.tgz#1c14479b40f1397a75782f115e4086447433a200"
|
||||
|
Loading…
x
Reference in New Issue
Block a user