From 9571d70cfba1effca2b1436374af3c9e06a49247 Mon Sep 17 00:00:00 2001 From: amansinghbais Date: Tue, 17 Oct 2023 18:51:08 +0530 Subject: [PATCH] Improved: promise.allsettled response handling (#212) --- src/views/ClosePurchaseOrderModal.vue | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/src/views/ClosePurchaseOrderModal.vue b/src/views/ClosePurchaseOrderModal.vue index 5378e3a7..294af806 100644 --- a/src/views/ClosePurchaseOrderModal.vue +++ b/src/views/ClosePurchaseOrderModal.vue @@ -132,21 +132,14 @@ export default defineComponent({ }, async updatePOItemStatus() { const eligibleItems = this.order.items.filter((item: any) => item.isChecked) - let failedItemsCount = 0; - await Promise.allSettled(eligibleItems.map(async (item:any) => { - const selectedItemDetails = { + const responses = await Promise.allSettled(eligibleItems.map(async (item: any) => { + await OrderService.updatePOItemStatus({ orderId: item.orderId, orderItemSeqId: item.orderItemSeqId, statusId: "ITEM_COMPLETED" - } - - try { - await OrderService.updatePOItemStatus(selectedItemDetails) - } catch(err) { - failedItemsCount++; - console.error(err); - } + }) })) + const failedItemsCount = responses.filter((response) => response.status === 'rejected').length if(failedItemsCount === 0){ showToast(translate('Purchase order updated successfully.'))