Skip to content

Commit

Permalink
feat: Added WPP.cart.remove function
Browse files Browse the repository at this point in the history
  • Loading branch information
icleitoncosta committed Jul 17, 2024
1 parent 5f205d0 commit ec01aac
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions src/cart/functions/remove.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*!
* Copyright 2024 WPPConnect Team
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

/**
* Remove a product in cart
*
* @example
* ```javascript
* const cart = WPP.cart.remove('[number]@c.us', '6987301181294productId');
* ```
*
* @category Cart
*/

import { WPPError } from '../../util';
import { CartModel, CartStore } from '../../whatsapp';
import { deleteProductFromCart } from '../../whatsapp/functions';

export async function remove(
chatId: string,
productId: string
): Promise<CartModel | undefined> {
if (!chatId || !productId) {
throw new WPPError(
'send_required_params',
`For update item in cart send chatId and productId`
);
}
await deleteProductFromCart(chatId, productId);
return CartStore.findCart(chatId);
}

0 comments on commit ec01aac

Please sign in to comment.