From 9ad2dd237db962a015bce2f191c880cfc91d4d47 Mon Sep 17 00:00:00 2001 From: icleitoncosta Date: Sat, 22 Jun 2024 10:01:27 -0300 Subject: [PATCH] fix: Improovment WPP.order.get function --- src/order/functions/get.ts | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/src/order/functions/get.ts b/src/order/functions/get.ts index 7608a03496..fba814c9fa 100644 --- a/src/order/functions/get.ts +++ b/src/order/functions/get.ts @@ -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 @@ -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'); + } }