Skip to content

Commit

Permalink
Improved: the fetchOrderItems action of order(#386)
Browse files Browse the repository at this point in the history
  • Loading branch information
R-Sourabh committed May 23, 2024
1 parent 7666910 commit 3a2c3f6
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/store/modules/order/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,15 @@ const actions: ActionTree<OrderState , RootState> ={
const productIds: any = []
const orders = resp.data.grouped?.orderId?.groups.map((order: any) => {
const orderItem = order.doclist.docs[0]
let currentItem = {};
let currentItem: any = {};
let currentItemQty = 0;
const otherItemsObj: any = {};
order.doclist.docs.forEach((item: any) => {
order.doclist.docs.map((item: any) => {
if (item.productId == productId) {
currentItemQty += item.itemQuantity;
currentItem = item;
currentItemQty += item.itemQuantity;
if(!currentItem.productId) {
currentItem = item;
}
} else {
if (!otherItemsObj[item.productId]) {
otherItemsObj[item.productId] = { ...item, quantity: 0 };
Expand All @@ -75,6 +77,7 @@ const actions: ActionTree<OrderState , RootState> ={
otherItemsObj[item.productId].quantity += item.itemQuantity;
}
});

currentItem = { ...currentItem, quantity: currentItemQty };
const otherItems = Object.values(otherItemsObj);

Expand Down

0 comments on commit 3a2c3f6

Please sign in to comment.