From 8fe8b37115c3d4e36d77e4d617b1f094aaca5582 Mon Sep 17 00:00:00 2001 From: amansinghbais Date: Mon, 28 Oct 2024 18:45:49 +0530 Subject: [PATCH] Improved: closing purchase order item in sync (#386) --- src/components/ClosePurchaseOrderModal.vue | 35 ++++++++++++++-------- 1 file changed, 23 insertions(+), 12 deletions(-) diff --git a/src/components/ClosePurchaseOrderModal.vue b/src/components/ClosePurchaseOrderModal.vue index 5424a71a..36c6ba51 100644 --- a/src/components/ClosePurchaseOrderModal.vue +++ b/src/components/ClosePurchaseOrderModal.vue @@ -67,6 +67,7 @@ import { mapGetters, useStore } from 'vuex' import { OrderService } from "@/services/OrderService"; import { DxpShopifyImg, translate, getProductIdentificationValue, useProductIdentificationStore } from '@hotwax/dxp-components'; import { useRouter } from 'vue-router'; +import { hasError } from '@/utils'; export default defineComponent({ name: "ClosePurchaseOrderModal", @@ -130,20 +131,30 @@ export default defineComponent({ } const eligibleItems = this.order.items.filter((item: any) => item.isChecked && this.isPOItemStatusPending(item)) - const responses = await Promise.allSettled(eligibleItems.map(async (item: any) => { - await OrderService.updatePOItemStatus({ - orderId: item.orderId, - orderItemSeqId: item.orderItemSeqId, - statusId: "ITEM_COMPLETED" - }) - return item.orderItemSeqId - })) - const failedItemsCount = responses.filter((response) => response.status === 'rejected').length - if(failedItemsCount){ - console.error('Failed to update the status of purchase order items.') + let hasFailedItems = false; + let completedItems = [] as any; + + for(const item of eligibleItems) { + try{ + const resp = await OrderService.updatePOItemStatus({ + orderId: item.orderId, + orderItemSeqId: item.orderItemSeqId, + statusId: "ITEM_COMPLETED" + }) + + if(!hasError(resp)) { + completedItems.push(item.orderItemSeqId) + } else { + throw resp.data; + } + } catch(error: any) { + hasFailedItems = true; + } } - const completedItems = responses.filter((response) => response.status === 'fulfilled')?.map((response: any) => response.value) + if(hasFailedItems){ + console.error('Failed to update the status of purchase order items.') + } if(!completedItems.length) return;