From 8854566403b27c2189f2a19f07fc8f8425f7fa87 Mon Sep 17 00:00:00 2001 From: amansinghbais Date: Wed, 19 Jun 2024 23:13:17 +0530 Subject: [PATCH 1/4] Improved: logic for fetching inventory for store using pagination (#80) --- src/views/PickupLocationModal.vue | 32 +++++++++++++++++++++---------- 1 file changed, 22 insertions(+), 10 deletions(-) diff --git a/src/views/PickupLocationModal.vue b/src/views/PickupLocationModal.vue index e3e6d1f8..0db6ec9a 100644 --- a/src/views/PickupLocationModal.vue +++ b/src/views/PickupLocationModal.vue @@ -162,19 +162,31 @@ export default defineComponent({ async checkInventory(facilityIds: Array) { const productIds = this.shipGroup.items.map((item: any) => item.productId) + let isScrollable = true, viewSize = 100, 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 + }); - 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 >= total) isScrollable = false; + } } - return productInventoryResp.data.docs.filter((store: any) => store.atp > 0) + return productInventoryResp.filter((store: any) => store.atp > 0) } catch (error) { console.error(error) } From 6b67eaf5117452b29fc029c87667cbcafb67d493 Mon Sep 17 00:00:00 2001 From: amansinghbais Date: Thu, 20 Jun 2024 10:06:17 +0530 Subject: [PATCH 2/4] Improved: added viewIndex for looping in store inventory (#80) --- src/views/PickupLocationModal.vue | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/views/PickupLocationModal.vue b/src/views/PickupLocationModal.vue index 0db6ec9a..47b4b881 100644 --- a/src/views/PickupLocationModal.vue +++ b/src/views/PickupLocationModal.vue @@ -162,7 +162,7 @@ export default defineComponent({ async checkInventory(facilityIds: Array) { const productIds = this.shipGroup.items.map((item: any) => item.productId) - let isScrollable = true, viewSize = 100, total = 0; + let isScrollable = true, viewSize = 100, viewIndex = 0, total = 0; let productInventoryResp = [] as any; try { @@ -173,7 +173,8 @@ export default defineComponent({ "facilityId": facilityIds }, "fieldsToSelect": ["productId", "atp", "facilityName", "facilityId"], - viewSize + viewSize, + viewIndex }); if(!hasError(resp) && resp.data.count) { @@ -184,6 +185,7 @@ export default defineComponent({ productInventoryResp = productInventoryResp.concat(resp.data.docs) } if(productInventoryResp >= total) isScrollable = false; + viewIndex++; } } return productInventoryResp.filter((store: any) => store.atp > 0) From 53542b53eae9d57357cd1180d6dc3f3e74fc52bd Mon Sep 17 00:00:00 2001 From: amansinghbais Date: Thu, 20 Jun 2024 10:07:14 +0530 Subject: [PATCH 3/4] Improved: viewSize to 250 for fetching inventory (#80) --- src/views/PickupLocationModal.vue | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/views/PickupLocationModal.vue b/src/views/PickupLocationModal.vue index 47b4b881..3f996660 100644 --- a/src/views/PickupLocationModal.vue +++ b/src/views/PickupLocationModal.vue @@ -162,7 +162,7 @@ export default defineComponent({ async checkInventory(facilityIds: Array) { const productIds = this.shipGroup.items.map((item: any) => item.productId) - let isScrollable = true, viewSize = 100, viewIndex = 0, total = 0; + let isScrollable = true, viewSize = 250, viewIndex = 0, total = 0; let productInventoryResp = [] as any; try { From fed6971f99c49bc8db1845ba8b926ca3d8a315ad Mon Sep 17 00:00:00 2001 From: amansinghbais Date: Thu, 20 Jun 2024 18:40:49 +0530 Subject: [PATCH 4/4] Improved: making a unique list of productIds and improved check for looping stop (#80) --- src/views/PickupLocationModal.vue | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/views/PickupLocationModal.vue b/src/views/PickupLocationModal.vue index 3f996660..665d5675 100644 --- a/src/views/PickupLocationModal.vue +++ b/src/views/PickupLocationModal.vue @@ -160,8 +160,7 @@ export default defineComponent({ } }, - async checkInventory(facilityIds: Array) { - const productIds = this.shipGroup.items.map((item: any) => item.productId) + async checkInventory(facilityIds: Array, productIds: Array) { let isScrollable = true, viewSize = 250, viewIndex = 0, total = 0; let productInventoryResp = [] as any; @@ -184,7 +183,7 @@ export default defineComponent({ } else { productInventoryResp = productInventoryResp.concat(resp.data.docs) } - if(productInventoryResp >= total) isScrollable = false; + if(productInventoryResp.length >= total) isScrollable = false; viewIndex++; } } @@ -210,10 +209,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);