Add quote calculations support
Some checks failed
Build Docker Image / build (push) Failing after 23s

This commit is contained in:
Ruslan Bakiev
2026-02-06 19:07:20 +07:00
parent 1287ae9db7
commit 2939482fc3
4 changed files with 111 additions and 43 deletions

View File

@@ -85,32 +85,11 @@
<script setup lang="ts">
import { GetOffersDocument, GetOfferDocument, type GetOffersQueryVariables } from '~/composables/graphql/public/exchange-generated'
import { GetNodeDocument, NearestOffersDocument } from '~/composables/graphql/public/geo-generated'
import { GetNodeDocument, NearestOffersDocument, QuoteCalculationsDocument, type QuoteCalculationsQueryResult } from '~/composables/graphql/public/geo-generated'
import type { MapBounds } from '~/components/catalog/CatalogMap.vue'
type QuoteOffer = {
uuid: string
productUuid?: string | null
productName?: string | null
supplierUuid?: string | null
supplierName?: string | null
teamUuid?: string | null
quantity?: number | string | null
unit?: string | null
pricePerUnit?: number | string | null
currency?: string | null
locationName?: string | null
locationCountry?: string | null
routes?: Array<{
totalTimeSeconds?: number | null
stages?: Array<{
transportType?: string | null
distanceKm?: number | null
travelTimeSeconds?: number | null
fromName?: string | null
} | null> | null
} | null> | null
}
type QuoteCalculation = NonNullable<NonNullable<QuoteCalculationsQueryResult['quoteCalculations']>[number]>
type QuoteOffer = NonNullable<NonNullable<QuoteCalculation['offers']>[number]>
definePageMeta({
layout: 'topnav'
@@ -417,14 +396,7 @@ const relatedPoints = computed(() => {
// Offers data for quote results
const offers = ref<QuoteOffer[]>([])
const quoteCalculations = computed(() => {
if (!offers.value.length) return []
return offers.value.map(offer => ({
id: offer.uuid,
offers: [offer]
}))
})
const quoteCalculations = ref<QuoteCalculation[]>([])
const offersLoading = ref(false)
const showQuoteResults = ref(false)
@@ -490,6 +462,7 @@ const onMapSelect = async (item: MapSelectItem) => {
selectItem('hub', itemId, itemName)
showQuoteResults.value = false
offers.value = []
quoteCalculations.value = []
return
}
@@ -498,6 +471,7 @@ const onMapSelect = async (item: MapSelectItem) => {
selectItem('supplier', itemId, itemName)
showQuoteResults.value = false
offers.value = []
quoteCalculations.value = []
return
}
@@ -510,6 +484,7 @@ const onMapSelect = async (item: MapSelectItem) => {
selectItem('product', offer.productUuid, offer.productName || itemName)
showQuoteResults.value = false
offers.value = []
quoteCalculations.value = []
}
return
}
@@ -610,25 +585,31 @@ 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 geoData = await execute(
NearestOffersDocument,
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: 12
limit: 10
},
'public',
'geo'
)
let nearest = (geoData?.nearestOffers || []).filter((o): o is QuoteOffer => o !== null)
let calculations = (calcData?.quoteCalculations || []).filter((c): c is QuoteCalculation => c !== null)
if (supplierId.value) {
nearest = nearest.filter(o => o?.supplierUuid === 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)
}
offers.value = 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) {
@@ -636,6 +617,7 @@ const onSearch = async () => {
}
} else {
offers.value = []
quoteCalculations.value = []
}
} else {
const vars: GetOffersQueryVariables = {}
@@ -657,6 +639,9 @@ const onSearch = async () => {
locationName: offer.locationName,
locationCountry: offer.locationCountry
}))
quoteCalculations.value = offers.value.map((offer) => ({
offers: [offer]
})) as QuoteCalculation[]
// Update labels from response
const first = offers.value[0]