mirror of
https://github.com/vercel/commerce.git
synced 2025-07-25 11:11:24 +00:00
@@ -1 +0,0 @@
|
||||
export default function noopApi(...args: any[]): void {}
|
@@ -1 +0,0 @@
|
||||
export default function noopApi(...args: any[]): void {}
|
@@ -0,0 +1,23 @@
|
||||
import catalogItemsQuery from '@framework/utils/queries/catalog-items-query'
|
||||
import { normalizeProduct } from '@framework/utils'
|
||||
import type { ProductsEndpoint } from '.'
|
||||
|
||||
const getCart: ProductsEndpoint['handlers']['getProducts'] = async ({
|
||||
req,
|
||||
res,
|
||||
config,
|
||||
}) => {
|
||||
const {
|
||||
data: { catalogItems },
|
||||
} = await config.fetch(catalogItemsQuery, {
|
||||
variables: {
|
||||
shopIds: [config.shopId],
|
||||
},
|
||||
})
|
||||
|
||||
const products = catalogItems.map((item) => normalizeProduct(item))
|
||||
|
||||
res.status(200).json({ data: products ?? null })
|
||||
}
|
||||
|
||||
export default getCart
|
@@ -0,0 +1,19 @@
|
||||
import { CommerceAPI, createEndpoint, GetAPISchema } from '@commerce/api'
|
||||
import productsEndpoint from '@commerce/api/endpoints/catalog/products'
|
||||
import type { ProductsSchema } from '@commerce/types/product'
|
||||
import getProducts from './get-products'
|
||||
|
||||
export type ProductsAPI = GetAPISchema<CommerceAPI, ProductsSchema>
|
||||
|
||||
export type ProductsEndpoint = ProductsAPI['endpoint']
|
||||
|
||||
export const handlers: ProductsEndpoint['handlers'] = {
|
||||
getProducts,
|
||||
}
|
||||
|
||||
const productsApi = createEndpoint<ProductsAPI>({
|
||||
handler: productsEndpoint,
|
||||
handlers,
|
||||
})
|
||||
|
||||
export default productsApi
|
Reference in New Issue
Block a user