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

@@ -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 })
}