Skip to content

Commit

Permalink
Merge branch 'hotwax:main' into #83
Browse files Browse the repository at this point in the history
  • Loading branch information
Sandesh3003 authored Jun 21, 2024
2 parents ca7f332 + 0fd583d commit 8f9f063
Showing 1 changed file with 27 additions and 14 deletions.
41 changes: 27 additions & 14 deletions src/views/PickupLocationModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -165,21 +165,34 @@ export default defineComponent({
}
},
async checkInventory(facilityIds: Array<string>) {
const productIds = this.shipGroup.items.map((item: any) => item.productId)
async checkInventory(facilityIds: Array<string>, productIds: Array<string>) {
let isScrollable = true, viewSize = 250, viewIndex = 0, total = 0;
let productInventoryResp = [] as any;
try {
const productInventoryResp = await StockService.checkInventory({
"filters": {
"productId": productIds,
"facilityId": facilityIds
},
"fieldsToSelect": ["productId", "atp", "facilityName", "facilityId"],
});
while(isScrollable) {
const resp = await StockService.checkInventory({
"filters": {
"productId": productIds,
"facilityId": facilityIds
},
"fieldsToSelect": ["productId", "atp", "facilityName", "facilityId"],
viewSize,
viewIndex
});
if (hasError(productInventoryResp) || !productInventoryResp.data.count) {
return [];
if(!hasError(resp) && resp.data.count) {
if(!productInventoryResp.length) {
productInventoryResp = resp.data.docs
total = resp.data.count;
} else {
productInventoryResp = productInventoryResp.concat(resp.data.docs)
}
if(productInventoryResp.length >= total) isScrollable = false;
viewIndex++;
}
}
return productInventoryResp.data.docs.filter((store: any) => store.atp > 0)
return productInventoryResp.filter((store: any) => store.atp > 0)
} catch (error) {
console.error(error)
}
Expand All @@ -201,10 +214,10 @@ export default defineComponent({
if (!stores?.length) return;
const facilityIds = stores.map((store: any) => store.storeCode)
const storesWithInventory = await this.checkInventory(facilityIds)
const productIds = [...new Set(this.shipGroup.items.map((item: any) => item.productId))] as any;
const storesWithInventory = await this.checkInventory(facilityIds, productIds)
if (!storesWithInventory?.length) return;
const productIds = this.shipGroup.items.map((item: any) => item.productId)
stores.map((storeData: any) => {
const inventoryDetails = storesWithInventory.filter((store: any) => store.facilityId === storeData.storeCode);
Expand Down

0 comments on commit 8f9f063

Please sign in to comment.