Fallback to nearest offers when calculations unavailable
Some checks failed
Build Docker Image / build (push) Failing after 24s
Some checks failed
Build Docker Image / build (push) Failing after 24s
This commit is contained in:
@@ -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,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]
|
||||
|
||||
Reference in New Issue
Block a user