mirror of
https://github.com/vercel/commerce.git
synced 2025-07-04 20:21:21 +00:00
* folder and env setup * codegen.json headers removed * use-cart code flow updated * use-cart code flow updated * Implemented get-cart functionality * removed unused file * getAnonymousShopperToken function added * normalization mapping updated * PR points resolved * Anonymous shopper token query added * getAnonymousShopperToken function added * Anonymous shopper token query added Co-authored-by: Chandradeepta <43542673+Chandradeepta@users.noreply.github.com>
24 lines
588 B
TypeScript
24 lines
588 B
TypeScript
import { normalizeCart } from '@framework/lib/normalize'
|
|
import { Cart } from '@framework/schema'
|
|
import type { CartEndpoint } from '.'
|
|
import { getCartQuery } from '../../queries/getCartQuery'
|
|
|
|
const getCart: CartEndpoint['handlers']['getCart'] = async ({
|
|
res,
|
|
body: { cartId },
|
|
config,
|
|
}) => {
|
|
let currentCart: Cart = {}
|
|
try {
|
|
let result = await config.fetch(getCartQuery)
|
|
currentCart = result?.data?.currentCart
|
|
} catch (error) {
|
|
throw error
|
|
}
|
|
res.status(200).json({
|
|
data: currentCart ? normalizeCart(currentCart) : null,
|
|
})
|
|
}
|
|
|
|
export default getCart
|