Skip to content

Commit

Permalink
Improved: promise.allsettled response handling (#212)
Browse files Browse the repository at this point in the history
  • Loading branch information
amansinghbais committed Oct 17, 2023
1 parent f6ea9d5 commit 9571d70
Showing 1 changed file with 4 additions and 11 deletions.
15 changes: 4 additions & 11 deletions src/views/ClosePurchaseOrderModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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.'))
Expand Down

0 comments on commit 9571d70

Please sign in to comment.