Fix potential body bug

This commit is contained in:
Luis Alvarez 2020-10-20 13:49:17 -05:00
parent b10dbbe2c3
commit ef81a968af
4 changed files with 12 additions and 13 deletions

View File

@ -80,19 +80,19 @@ const cartApi: BigcommerceApiHandler<Cart, CartHandlers> = async (
// Create or add an item to the cart
if (req.method === 'POST') {
const body = { cartId, ...req.body }
const body = { ...req.body, cartId }
return await handlers['addItem']({ req, res, config, body })
}
// Update item in cart
if (req.method === 'PUT') {
const body = { cartId, ...req.body }
const body = { ...req.body, cartId }
return await handlers['updateItem']({ req, res, config, body })
}
// Remove an item from the cart
if (req.method === 'DELETE') {
const body = { cartId, ...req.body }
const body = { ...req.body, cartId }
return await handlers['removeItem']({ req, res, config, body })
}
} catch (error) {

View File

@ -38,7 +38,7 @@ const customersApi: BigcommerceApiHandler<Customer, CustomersHandlers> = async (
try {
if (req.method === 'POST') {
const body = { cartId, ...req.body }
const body = { ...req.body, cartId }
return await handlers['createCustomer']({ req, res, config, body })
}
} catch (error) {

View File

@ -47,7 +47,7 @@ export type Wishlist = {
export type WishlistList = Wishlist[]
export type WishlistHandlers = {
getAllWishlists: BigcommerceHandler<WishlistList, { customerId?: string }>
getAllWishlists: BigcommerceHandler<WishlistList, { customerId?: string }>
getWishlist: BigcommerceHandler<Wishlist, { wishlistId?: string }>
addWishlist: BigcommerceHandler<
Wishlist,
@ -57,7 +57,10 @@ export type WishlistHandlers = {
Wishlist,
{ wishlistId: string } & Body<AddWishlistBody>
>
addItem: BigcommerceHandler<Wishlist, { wishlistId: string } & Body<AddItemBody>>
addItem: BigcommerceHandler<
Wishlist,
{ wishlistId: string } & Body<AddItemBody>
>
removeItem: BigcommerceHandler<
Wishlist,
{ wishlistId: string } & Body<RemoveItemBody>
@ -86,13 +89,13 @@ const wishlistApi: BigcommerceApiHandler<Wishlist, WishlistHandlers> = async (
// Add an item to the wishlist
if (req.method === 'POST' && wishlistId) {
const body = { wishlistId, ...req.body }
const body = { ...req.body, wishlistId }
return await handlers['addItem']({ req, res, config, body })
}
// Update a wishlist
if (req.method === 'PUT' && wishlistId) {
const body = { wishlistId, ...req.body }
const body = { ...req.body, wishlistId }
return await handlers['updateWishlist']({ req, res, config, body })
}

View File

@ -14,8 +14,4 @@ export interface CommerceAPIFetchOptions<V> {
preview?: boolean
}
// TODO: define interfaces for all the available operations
// export interface CommerceAPI {
// getAllProducts(options?: { query: string }): Promise<any>;
// }
// TODO: define interfaces for all the available operations and API endpoints