forked from crowetic/commerce
Fix potential body bug
This commit is contained in:
parent
b10dbbe2c3
commit
ef81a968af
@ -80,19 +80,19 @@ const cartApi: BigcommerceApiHandler<Cart, CartHandlers> = async (
|
|||||||
|
|
||||||
// Create or add an item to the cart
|
// Create or add an item to the cart
|
||||||
if (req.method === 'POST') {
|
if (req.method === 'POST') {
|
||||||
const body = { cartId, ...req.body }
|
const body = { ...req.body, cartId }
|
||||||
return await handlers['addItem']({ req, res, config, body })
|
return await handlers['addItem']({ req, res, config, body })
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update item in cart
|
// Update item in cart
|
||||||
if (req.method === 'PUT') {
|
if (req.method === 'PUT') {
|
||||||
const body = { cartId, ...req.body }
|
const body = { ...req.body, cartId }
|
||||||
return await handlers['updateItem']({ req, res, config, body })
|
return await handlers['updateItem']({ req, res, config, body })
|
||||||
}
|
}
|
||||||
|
|
||||||
// Remove an item from the cart
|
// Remove an item from the cart
|
||||||
if (req.method === 'DELETE') {
|
if (req.method === 'DELETE') {
|
||||||
const body = { cartId, ...req.body }
|
const body = { ...req.body, cartId }
|
||||||
return await handlers['removeItem']({ req, res, config, body })
|
return await handlers['removeItem']({ req, res, config, body })
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
@ -38,7 +38,7 @@ const customersApi: BigcommerceApiHandler<Customer, CustomersHandlers> = async (
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
if (req.method === 'POST') {
|
if (req.method === 'POST') {
|
||||||
const body = { cartId, ...req.body }
|
const body = { ...req.body, cartId }
|
||||||
return await handlers['createCustomer']({ req, res, config, body })
|
return await handlers['createCustomer']({ req, res, config, body })
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
@ -47,7 +47,7 @@ export type Wishlist = {
|
|||||||
export type WishlistList = Wishlist[]
|
export type WishlistList = Wishlist[]
|
||||||
|
|
||||||
export type WishlistHandlers = {
|
export type WishlistHandlers = {
|
||||||
getAllWishlists: BigcommerceHandler<WishlistList, { customerId?: string }>
|
getAllWishlists: BigcommerceHandler<WishlistList, { customerId?: string }>
|
||||||
getWishlist: BigcommerceHandler<Wishlist, { wishlistId?: string }>
|
getWishlist: BigcommerceHandler<Wishlist, { wishlistId?: string }>
|
||||||
addWishlist: BigcommerceHandler<
|
addWishlist: BigcommerceHandler<
|
||||||
Wishlist,
|
Wishlist,
|
||||||
@ -57,7 +57,10 @@ export type WishlistHandlers = {
|
|||||||
Wishlist,
|
Wishlist,
|
||||||
{ wishlistId: string } & Body<AddWishlistBody>
|
{ wishlistId: string } & Body<AddWishlistBody>
|
||||||
>
|
>
|
||||||
addItem: BigcommerceHandler<Wishlist, { wishlistId: string } & Body<AddItemBody>>
|
addItem: BigcommerceHandler<
|
||||||
|
Wishlist,
|
||||||
|
{ wishlistId: string } & Body<AddItemBody>
|
||||||
|
>
|
||||||
removeItem: BigcommerceHandler<
|
removeItem: BigcommerceHandler<
|
||||||
Wishlist,
|
Wishlist,
|
||||||
{ wishlistId: string } & Body<RemoveItemBody>
|
{ wishlistId: string } & Body<RemoveItemBody>
|
||||||
@ -86,13 +89,13 @@ const wishlistApi: BigcommerceApiHandler<Wishlist, WishlistHandlers> = async (
|
|||||||
|
|
||||||
// Add an item to the wishlist
|
// Add an item to the wishlist
|
||||||
if (req.method === 'POST' && wishlistId) {
|
if (req.method === 'POST' && wishlistId) {
|
||||||
const body = { wishlistId, ...req.body }
|
const body = { ...req.body, wishlistId }
|
||||||
return await handlers['addItem']({ req, res, config, body })
|
return await handlers['addItem']({ req, res, config, body })
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update a wishlist
|
// Update a wishlist
|
||||||
if (req.method === 'PUT' && wishlistId) {
|
if (req.method === 'PUT' && wishlistId) {
|
||||||
const body = { wishlistId, ...req.body }
|
const body = { ...req.body, wishlistId }
|
||||||
return await handlers['updateWishlist']({ req, res, config, body })
|
return await handlers['updateWishlist']({ req, res, config, body })
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -14,8 +14,4 @@ export interface CommerceAPIFetchOptions<V> {
|
|||||||
preview?: boolean
|
preview?: boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: define interfaces for all the available operations
|
// TODO: define interfaces for all the available operations and API endpoints
|
||||||
|
|
||||||
// export interface CommerceAPI {
|
|
||||||
// getAllProducts(options?: { query: string }): Promise<any>;
|
|
||||||
// }
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user