Skip to content

Commit

Permalink
feat: Added WPP.cart.update function
Browse files Browse the repository at this point in the history
  • Loading branch information
icleitoncosta committed Jul 17, 2024
1 parent ec01aac commit 011fcdc
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions src/cart/functions/update.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.
*/

/**
* Update product in cart
*
* @example
* ```javascript
* const cart = WPP.cart.update('[number]@c.us', '6987301181294productId', { quantity: 12 });
* ```
*
* @category Cart
*/

import { WPPError } from '../../util';
import { CartModel } from '../../whatsapp';
import { add } from './add';

export async function update(
chatId: string,
productId: string,
options: { quantity: number }
): Promise<CartModel | undefined> {
if (!chatId || !productId || !options.quantity) {
throw new WPPError(
'send_required_params',
`For update item in cart send chatId, productId and options`
);
}
return add(chatId, [{ id: productId, qnt: options.quantity }]);
}

0 comments on commit 011fcdc

Please sign in to comment.