mirror of
https://github.com/vercel/commerce.git
synced 2025-06-20 06:01:21 +00:00
chore: setup commerce & next config fix: replace all call to bigcommerce from aquilacms provider feat add validation to input in signup
41 lines
1.1 KiB
TypeScript
41 lines
1.1 KiB
TypeScript
import type { AquilacmsCart } from '../../../types'
|
|
import { AquilacmsApiError } from '../../utils/errors'
|
|
import getCartCookie from '../../utils/get-cart-cookie'
|
|
import type { CartHandlers } from '..'
|
|
import { normalizeCart } from '../../../lib/normalize'
|
|
|
|
// Return current cart info
|
|
const getCart: CartHandlers['getCart'] = async ({
|
|
res,
|
|
body: { cartId },
|
|
config,
|
|
}) => {
|
|
if (cartId) {
|
|
try {
|
|
let result: AquilacmsCart = await config.storeApiFetch(
|
|
`/v2/cart/${cartId}`,
|
|
{
|
|
method: 'POST',
|
|
body: JSON.stringify({
|
|
lang: 'en',
|
|
PostBody: {
|
|
populate: ['items.id'],
|
|
},
|
|
}),
|
|
}
|
|
)
|
|
return res.status(200).json({ data: normalizeCart(result) })
|
|
} catch (error) {
|
|
if (error instanceof AquilacmsApiError && error.status === 404) {
|
|
// Remove the cookie if it exists but the cart wasn't found
|
|
res.setHeader('Set-Cookie', getCartCookie(config.cartCookie))
|
|
} else {
|
|
throw error
|
|
}
|
|
}
|
|
}
|
|
res.status(200).json({ data: null })
|
|
}
|
|
|
|
export default getCart
|