Fallback to nearest offers when calculations unavailable
Some checks failed
Build Docker Image / build (push) Failing after 24s

This commit is contained in:
Ruslan Bakiev
2026-02-06 19:12:48 +07:00
parent c5d1dc87ae
commit 795aa0381e

View File

@@ -397,6 +397,9 @@ const relatedPoints = computed(() => {
// Offers data for quote results
const offers = ref<QuoteOffer[]>([])
const quoteCalculations = ref<QuoteCalculation[]>([])
const buildCalculationsFromOffers = (list: QuoteOffer[]) =>
list.map((offer) => ({ offers: [offer] })) as QuoteCalculation[]
const offersLoading = ref(false)
const showQuoteResults = ref(false)
@@ -585,6 +588,7 @@ const onSearch = async () => {
const hubData = await execute(GetNodeDocument, { uuid: hubId.value }, 'public', 'geo')
const hub = hubData?.node
if (hub?.latitude != null && hub?.longitude != null) {
try {
const calcData = await execute(
QuoteCalculationsDocument,
{
@@ -610,6 +614,29 @@ const onSearch = async () => {
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)
}
const first = offers.value[0]
if (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]