Skip to content

Commit

Permalink
fix: Improovment WPP.order.get function
Browse files Browse the repository at this point in the history
  • Loading branch information
icleitoncosta committed Jun 22, 2024
1 parent bc0cd96 commit 9ad2dd2
Showing 1 changed file with 21 additions and 4 deletions.
25 changes: 21 additions & 4 deletions src/order/functions/get.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,11 @@
*/

import { WPPError } from '../../util';
import { MsgKey, MsgStore } from '../../whatsapp';
import { getOrderInfo } from '../../whatsapp/functions';
import { MsgKey, MsgStore, OrderModel } from '../../whatsapp';
import { MSG_TYPE } from '../../whatsapp/enums';
import { queryOrder } from '../../whatsapp/functions';
/**
* Get info of your sended order
* Get info of a order
*
* @example
* ```javascript
Expand All @@ -30,5 +31,21 @@ import { getOrderInfo } from '../../whatsapp/functions';
export async function get(msgId: string | MsgKey) {
const msg = MsgStore.get(msgId);
if (!msg) throw new WPPError('msg_not_found', 'Message not found');
return await getOrderInfo(msg);
if (msg.type === MSG_TYPE.ORDER) {
const order = await queryOrder(msg.orderId, 80, 80, msg.token);
const model = new OrderModel({
id: msg.orderId,
products: order.products,
itemCount: order.products.length,
subtotal: order.subtotal,
tax: order.tax,
total: order.total,
currency: order.currency,
createdAt: order.createdAt,
sellerJid: msg.sellerJid,
});
return model;
} else {
throw new WPPError('msg_not_is_a_order', 'Message not is a order');
}
}

0 comments on commit 9ad2dd2

Please sign in to comment.