kibo-chandradeeptalaha 0e5c68ef58
Feature/icky 194 (#5)
* 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>
2021-08-30 10:41:10 -05:00

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