From 795aa0381edf24e48ee53b624ec9cdc2280ca06b Mon Sep 17 00:00:00 2001 From: Ruslan Bakiev <572431+veikab@users.noreply.github.com> Date: Fri, 6 Feb 2026 19:12:48 +0700 Subject: [PATCH] Fallback to nearest offers when calculations unavailable --- app/pages/catalog/index.vue | 77 ++++++++++++++++++++++++------------- 1 file changed, 51 insertions(+), 26 deletions(-) diff --git a/app/pages/catalog/index.vue b/app/pages/catalog/index.vue index 23df3f2..f5b1652 100644 --- a/app/pages/catalog/index.vue +++ b/app/pages/catalog/index.vue @@ -397,6 +397,9 @@ const relatedPoints = computed(() => { // Offers data for quote results const offers = ref([]) const quoteCalculations = ref([]) + +const buildCalculationsFromOffers = (list: QuoteOffer[]) => + list.map((offer) => ({ offers: [offer] })) as QuoteCalculation[] const offersLoading = ref(false) const showQuoteResults = ref(false) @@ -585,32 +588,56 @@ const onSearch = async () => { const hubData = await execute(GetNodeDocument, { uuid: hubId.value }, 'public', 'geo') const hub = hubData?.node if (hub?.latitude != null && hub?.longitude != null) { - const calcData = await execute( - QuoteCalculationsDocument, - { - lat: hub.latitude, - lon: hub.longitude, - productUuid: productId.value, - hubUuid: hubId.value, - quantity: quantity.value ? Number(quantity.value) : null, - radius: 500, - limit: 10 - }, - 'public', - 'geo' - ) + try { + const calcData = await execute( + QuoteCalculationsDocument, + { + lat: hub.latitude, + lon: hub.longitude, + productUuid: productId.value, + hubUuid: hubId.value, + quantity: quantity.value ? Number(quantity.value) : null, + radius: 500, + limit: 10 + }, + 'public', + 'geo' + ) - let calculations = (calcData?.quoteCalculations || []).filter((c): c is QuoteCalculation => c !== null) - if (supplierId.value) { - calculations = calculations.map((calc) => ({ - ...calc, - offers: (calc.offers || []).filter((offer): offer is QuoteOffer => offer !== null).filter(offer => offer.supplierUuid === supplierId.value) - })).filter(calc => calc.offers.length > 0) + let calculations = (calcData?.quoteCalculations || []).filter((c): c is QuoteCalculation => c !== null) + if (supplierId.value) { + calculations = calculations.map((calc) => ({ + ...calc, + offers: (calc.offers || []).filter((offer): offer is QuoteOffer => offer !== null).filter(offer => offer.supplierUuid === supplierId.value) + })).filter(calc => calc.offers.length > 0) + } + + quoteCalculations.value = calculations + offers.value = calculations.flatMap(calc => (calc.offers || []).filter((offer): offer is QuoteOffer => offer !== null)) + } catch (error) { + const geoData = await execute( + NearestOffersDocument, + { + lat: hub.latitude, + lon: hub.longitude, + productUuid: productId.value, + hubUuid: hubId.value, + radius: 500, + limit: 12 + }, + 'public', + 'geo' + ) + + let nearest = (geoData?.nearestOffers || []).filter((o): o is QuoteOffer => o !== null) + if (supplierId.value) { + nearest = nearest.filter(o => o?.supplierUuid === supplierId.value) + } + + offers.value = nearest + quoteCalculations.value = buildCalculationsFromOffers(nearest) } - quoteCalculations.value = calculations - offers.value = calculations.flatMap(calc => (calc.offers || []).filter((offer): offer is QuoteOffer => offer !== null)) - const first = offers.value[0] if (first?.productName) { setLabel('product', productId.value, first.productName) @@ -639,9 +666,7 @@ const onSearch = async () => { locationName: offer.locationName, locationCountry: offer.locationCountry })) - quoteCalculations.value = offers.value.map((offer) => ({ - offers: [offer] - })) as QuoteCalculation[] + quoteCalculations.value = buildCalculationsFromOffers(offers.value) // Update labels from response const first = offers.value[0]