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 // Offers data for quote results
const offers = ref<QuoteOffer[]>([]) const offers = ref<QuoteOffer[]>([])
const quoteCalculations = ref<QuoteCalculation[]>([]) const quoteCalculations = ref<QuoteCalculation[]>([])
const buildCalculationsFromOffers = (list: QuoteOffer[]) =>
list.map((offer) => ({ offers: [offer] })) as QuoteCalculation[]
const offersLoading = ref(false) const offersLoading = ref(false)
const showQuoteResults = ref(false) const showQuoteResults = ref(false)
@@ -585,32 +588,56 @@ const onSearch = async () => {
const hubData = await execute(GetNodeDocument, { uuid: hubId.value }, 'public', 'geo') const hubData = await execute(GetNodeDocument, { uuid: hubId.value }, 'public', 'geo')
const hub = hubData?.node const hub = hubData?.node
if (hub?.latitude != null && hub?.longitude != null) { if (hub?.latitude != null && hub?.longitude != null) {
const calcData = await execute( try {
QuoteCalculationsDocument, const calcData = await execute(
{ QuoteCalculationsDocument,
lat: hub.latitude, {
lon: hub.longitude, lat: hub.latitude,
productUuid: productId.value, lon: hub.longitude,
hubUuid: hubId.value, productUuid: productId.value,
quantity: quantity.value ? Number(quantity.value) : null, hubUuid: hubId.value,
radius: 500, quantity: quantity.value ? Number(quantity.value) : null,
limit: 10 radius: 500,
}, limit: 10
'public', },
'geo' 'public',
) 'geo'
)
let calculations = (calcData?.quoteCalculations || []).filter((c): c is QuoteCalculation => c !== null) let calculations = (calcData?.quoteCalculations || []).filter((c): c is QuoteCalculation => c !== null)
if (supplierId.value) { if (supplierId.value) {
calculations = calculations.map((calc) => ({ calculations = calculations.map((calc) => ({
...calc, ...calc,
offers: (calc.offers || []).filter((offer): offer is QuoteOffer => offer !== null).filter(offer => offer.supplierUuid === supplierId.value) offers: (calc.offers || []).filter((offer): offer is QuoteOffer => offer !== null).filter(offer => offer.supplierUuid === supplierId.value)
})).filter(calc => calc.offers.length > 0) })).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] const first = offers.value[0]
if (first?.productName) { if (first?.productName) {
setLabel('product', productId.value, first.productName) setLabel('product', productId.value, first.productName)
@@ -639,9 +666,7 @@ const onSearch = async () => {
locationName: offer.locationName, locationName: offer.locationName,
locationCountry: offer.locationCountry locationCountry: offer.locationCountry
})) }))
quoteCalculations.value = offers.value.map((offer) => ({ quoteCalculations.value = buildCalculationsFromOffers(offers.value)
offers: [offer]
})) as QuoteCalculation[]
// Update labels from response // Update labels from response
const first = offers.value[0] const first = offers.value[0]