Skip to content

Commit

Permalink
Improved: Refactor deliverShipment method to remove async/await and p…
Browse files Browse the repository at this point in the history
…romise logic(#468)
  • Loading branch information
R-Sourabh committed Dec 9, 2024
1 parent e40e62a commit 2dd65ec
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions src/views/Orders.vue
Original file line number Diff line number Diff line change
Expand Up @@ -435,22 +435,21 @@ export default defineComponent({
},
async deliverShipment (order: any) {
await this.store.dispatch('order/deliverShipment', order)
.then(async (resp) => {
if(!hasError(resp)){
.then((resp) => {
if(!hasError(resp)) {
showToast(translate('Order delivered to', {customerName: order.customer.name}))
const productIds = [...new Set(order.parts.reduce((productId: any, part: any) => {
const ids = part.items.map((item: any) => item.productId)
return productId.concat(ids)
}, []))]
const fetchProductStock = productIds.map(async (productId: any) => {
productIds.map((productId: any) => {
const productStock = this.getProductStock(productId);
if (productStock && productStock.quantityOnHandTotal >= 0) {
return this.store.dispatch('stock/fetchStock', { productId })
this.store.dispatch('stock/fetchStock', { productId });
}
})
await Promise.allSettled(fetchProductStock);
}
})
},
Expand Down

0 comments on commit 2dd65ec

Please sign in to comment.