Update catalog pages to use new geo queries
Some checks failed
Build Docker Image / build (push) Failing after 1m35s

- Replace FindProductRoutesDocument with GetOffersToHubDocument
- Replace FindSupplierProductHubsDocument with GetOffersBySupplierProductDocument + GetHubsNearOfferDocument
- Update all catalog pages to use new query naming convention
- Add new GraphQL operation files, remove deprecated ones
This commit is contained in:
Ruslan Bakiev
2026-01-16 15:40:06 +07:00
parent e869c2065f
commit 2253cd20b0
19 changed files with 232 additions and 188 deletions

View File

@@ -1,4 +1,4 @@
import { GetAvailableProductsDocument } from '~/composables/graphql/public/exchange-generated'
import { GetProductsDocument } from '~/composables/graphql/public/geo-generated'
// Shared state
const items = ref<any[]>([])
@@ -13,12 +13,12 @@ export function useCatalogProducts() {
isLoading.value = true
try {
const data = await execute(
GetAvailableProductsDocument,
GetProductsDocument,
{},
'public',
'exchange'
'geo'
)
items.value = data?.getAvailableProducts || []
items.value = data?.products || []
isInitialized.value = true
} finally {
isLoading.value = false

View File

@@ -94,7 +94,7 @@
</template>
<script setup lang="ts">
import { GetNodeConnectionsDocument, FindProductRoutesDocument } from '~/composables/graphql/public/geo-generated'
import { GetNodeConnectionsDocument, GetOffersToHubDocument } from '~/composables/graphql/public/geo-generated'
import { GetAvailableProductsDocument, GetOfferDocument } from '~/composables/graphql/public/exchange-generated'
definePageMeta({
@@ -225,7 +225,7 @@ const loadOfferDetails = async () => {
offersData.value = newOffersData
}
// Load routes
// Load offers with routes to this hub
const loadRoutes = async () => {
if (!productId.value || !hubId.value) {
rawSources.value = []
@@ -238,20 +238,19 @@ const loadRoutes = async () => {
try {
const data = await execute(
FindProductRoutesDocument,
GetOffersToHubDocument,
{
hubUuid: hubId.value,
productUuid: productId.value,
toUuid: hubId.value,
limitSources: 12,
limitRoutes: 1
limit: 12
},
'public',
'geo'
)
rawSources.value = (data?.findProductRoutes || []).filter(Boolean)
rawSources.value = (data?.offersToHub || []).filter(Boolean)
await loadOfferDetails()
} catch (error) {
console.error('Error loading routes:', error)
console.error('Error loading offers:', error)
rawSources.value = []
} finally {
isLoadingRoutes.value = false

View File

@@ -62,8 +62,7 @@
</template>
<script setup lang="ts">
import { GetNodeConnectionsDocument, FindProductsForHubDocument } from '~/composables/graphql/public/geo-generated'
import { GetAvailableProductsDocument } from '~/composables/graphql/public/exchange-generated'
import { GetNodeConnectionsDocument, GetProductsNearHubDocument } from '~/composables/graphql/public/geo-generated'
definePageMeta({
layout: 'topnav'
@@ -119,19 +118,17 @@ const getMockPriceHistory = (uuid: string): number[] => {
// Initial load
try {
const [{ data: connectionsData }, { data: productUuidsData }, { data: allProductsData }] = await Promise.all([
const [{ data: connectionsData }, { data: productsData }] = await Promise.all([
useServerQuery('hub-connections', GetNodeConnectionsDocument, { uuid: hubId.value }, 'public', 'geo'),
useServerQuery('hub-product-uuids', FindProductsForHubDocument, { hubUuid: hubId.value }, 'public', 'geo'),
useServerQuery('available-products', GetAvailableProductsDocument, {}, 'public', 'exchange')
useServerQuery('products-near-hub', GetProductsNearHubDocument, { hubUuid: hubId.value, radiusKm: 500 }, 'public', 'geo')
])
hub.value = connectionsData.value?.nodeConnections?.hub || null
// Filter products by UUIDs that can be delivered to this hub
const relevantUuids = new Set(productUuidsData.value?.findProductsForHub?.filter(Boolean) || [])
products.value = (allProductsData.value?.getAvailableProducts || [])
.filter((p): p is { uuid: string; name: string } => p !== null && !!p.uuid && !!p.name && relevantUuids.has(p.uuid))
.map(p => ({ uuid: p.uuid!, name: p.name! }))
// Get products near this hub (from geo)
products.value = (productsData.value?.productsNearHub || [])
.filter((p): p is { uuid: string; name?: string | null } => p !== null && !!p.uuid)
.map(p => ({ uuid: p.uuid!, name: p.name || '' }))
} catch (error) {
console.error('Error loading hub:', error)
} finally {

View File

@@ -94,7 +94,7 @@
</template>
<script setup lang="ts">
import { GetNodeConnectionsDocument, FindProductRoutesDocument } from '~/composables/graphql/public/geo-generated'
import { GetNodeConnectionsDocument, GetOffersToHubDocument } from '~/composables/graphql/public/geo-generated'
import { GetAvailableProductsDocument, GetOfferDocument } from '~/composables/graphql/public/exchange-generated'
definePageMeta({
@@ -225,7 +225,7 @@ const loadOfferDetails = async () => {
offersData.value = newOffersData
}
// Load routes
// Load offers with routes to this hub
const loadRoutes = async () => {
if (!productId.value || !hubId.value) {
rawSources.value = []
@@ -238,20 +238,19 @@ const loadRoutes = async () => {
try {
const data = await execute(
FindProductRoutesDocument,
GetOffersToHubDocument,
{
hubUuid: hubId.value,
productUuid: productId.value,
toUuid: hubId.value,
limitSources: 12,
limitRoutes: 1
limit: 12
},
'public',
'geo'
)
rawSources.value = (data?.findProductRoutes || []).filter(Boolean)
rawSources.value = (data?.offersToHub || []).filter(Boolean)
await loadOfferDetails()
} catch (error) {
console.error('Error loading routes:', error)
console.error('Error loading offers:', error)
rawSources.value = []
} finally {
isLoadingRoutes.value = false

View File

@@ -77,8 +77,7 @@
</template>
<script setup lang="ts">
import { GetAvailableProductsDocument } from '~/composables/graphql/public/exchange-generated'
import { FindHubsForProductDocument } from '~/composables/graphql/public/geo-generated'
import { GetOffersByProductDocument, GetHubsNearOfferDocument } from '~/composables/graphql/public/geo-generated'
definePageMeta({
layout: 'topnav'
@@ -155,29 +154,46 @@ const chartSeries = computed(() => [{
// Initial load
try {
const [{ data: productsData }, { data: hubsData }] = await Promise.all([
useServerQuery('product-info', GetAvailableProductsDocument, {}, 'public', 'exchange'),
useServerQuery('hubs-for-product', FindHubsForProductDocument, { productUuid: productId.value }, 'public', 'geo')
])
// Get offers for this product from geo
const { data: offersData } = await useServerQuery(
'offers-for-product',
GetOffersByProductDocument,
{ productUuid: productId.value },
'public',
'geo'
)
const foundProduct = (productsData.value?.getAvailableProducts || [])
.find(p => p?.uuid === productId.value)
const offers = offersData.value?.offersByProduct || []
if (foundProduct) {
product.value = { uuid: foundProduct.uuid!, name: foundProduct.name || '' }
if (offers.length > 0) {
const firstOffer = offers[0]
product.value = {
uuid: productId.value,
name: firstOffer?.productName || ''
}
// Get hubs near the first offer's location
if (firstOffer?.uuid) {
const { data: hubsData } = await useServerQuery(
'hubs-near-offer',
GetHubsNearOfferDocument,
{ offerUuid: firstOffer.uuid, limit: 12 },
'public',
'geo'
)
hubs.value = (hubsData.value?.hubsNearOffer || [])
.filter((h): h is NonNullable<typeof h> => h !== null && !!h.uuid && !!h.name)
.map(h => ({
uuid: h.uuid!,
name: h.name!,
latitude: h.latitude ?? undefined,
longitude: h.longitude ?? undefined,
country: h.country || undefined,
countryCode: h.countryCode || undefined
}))
}
}
// Get only hubs where this product can be delivered
hubs.value = (hubsData.value?.findHubsForProduct || [])
.filter((h): h is NonNullable<typeof h> => h !== null && !!h.uuid && !!h.name)
.map(h => ({
uuid: h.uuid!,
name: h.name!,
latitude: h.latitude ?? undefined,
longitude: h.longitude ?? undefined,
country: h.country || undefined,
countryCode: h.countryCode || undefined
}))
} catch (error) {
console.error('Error loading product hubs:', error)
} finally {

View File

@@ -126,12 +126,10 @@
</template>
<script setup lang="ts">
import { GetNodeConnectionsDocument, FindRoutesDocument } from '~/composables/graphql/public/geo-generated'
import { GetNodeConnectionsDocument, GetOffersBySupplierProductDocument, GetDeliveryToHubDocument } from '~/composables/graphql/public/geo-generated'
import {
GetSupplierProfileDocument,
GetSupplierOffersDocument,
GetSupplierProfilesDocument,
GetOffersDocument,
} from '~/composables/graphql/public/exchange-generated'
definePageMeta({
@@ -264,9 +262,9 @@ const chartSeries = computed(() => [{
data: priceHistory.value
}])
// Load route using FindRoutes (single source!)
const loadRoute = async () => {
if (!sourceLocation.value || !hubId.value) {
// Load route using delivery to hub
const loadRoute = async (offerUuid: string) => {
if (!offerUuid || !hubId.value) {
routeData.value = null
return
}
@@ -274,16 +272,15 @@ const loadRoute = async () => {
isLoadingRoute.value = true
try {
const data = await execute(
FindRoutesDocument,
GetDeliveryToHubDocument,
{
fromUuid: sourceLocation.value.uuid,
toUuid: hubId.value,
limit: 1
offerUuid,
hubUuid: hubId.value
},
'public',
'geo'
)
routeData.value = data?.findRoutes?.[0] || null
routeData.value = data?.deliveryToHub?.routes?.[0] || null
} catch (error) {
console.error('Error loading route:', error)
routeData.value = null
@@ -304,7 +301,7 @@ try {
)
hub.value = hubData.value?.nodeConnections?.hub || null
// Get supplier
// Get supplier profile from exchange
const { data: supplierData } = await useServerQuery(
'supplier-profile',
GetSupplierProfileDocument,
@@ -326,54 +323,41 @@ try {
.find((s: any) => s?.teamUuid === supplierId.value || s?.uuid === supplierId.value) || null
}
// Get supplier's offers to find product and source location
// Get offers for this supplier+product from geo
if (supplier.value) {
const teamIds = [supplier.value?.teamUuid, supplier.value?.uuid, supplierId.value].filter(Boolean)
const primaryId = teamIds[0] as string
const supplierUuidForGeo = supplier.value?.uuid || supplierId.value
const { data: offersData } = await useServerQuery(
'supplier-offers',
GetSupplierOffersDocument,
{ teamUuid: primaryId },
'supplier-product-offers',
GetOffersBySupplierProductDocument,
{ supplierUuid: supplierUuidForGeo, productUuid: productId.value },
'public',
'exchange'
'geo'
)
let offers = offersData.value?.getOffers || []
if (!offers.length) {
const { data: allOffersData } = await useServerQuery(
'supplier-offers-fallback',
GetOffersDocument,
{},
'public',
'exchange'
)
const ids = new Set(teamIds)
offers = (allOffersData.value?.getOffers || []).filter((o: any) => o?.teamUuid && ids.has(o.teamUuid))
}
const offers = offersData.value?.offersBySupplierProduct || []
// Find product and source location in offers
for (const offer of offers) {
const line = offer.lines?.find((l: any) => l?.productUuid === productId.value)
if (line) {
product.value = { uuid: line.productUuid, name: line.productName }
if (offer.locationUuid && offer.locationName) {
sourceLocation.value = {
uuid: offer.locationUuid,
name: offer.locationName,
latitude: offer.locationLat,
longitude: offer.locationLon
}
// Use first offer for product info and source location
if (offers.length > 0) {
const firstOffer = offers[0]
if (firstOffer?.productUuid && firstOffer?.productName) {
product.value = { uuid: firstOffer.productUuid, name: firstOffer.productName }
}
if (firstOffer?.latitude && firstOffer?.longitude) {
sourceLocation.value = {
uuid: firstOffer.uuid || '',
name: firstOffer.country || 'Origin',
latitude: firstOffer.latitude,
longitude: firstOffer.longitude
}
break
}
// Load route using the offer UUID
if (firstOffer?.uuid && hub.value) {
await loadRoute(firstOffer.uuid)
}
}
}
// Load route after getting source location
if (sourceLocation.value && hub.value) {
await loadRoute()
}
} catch (error) {
console.error('Error loading data:', error)
} finally {

View File

@@ -92,12 +92,10 @@
</template>
<script setup lang="ts">
import { FindSupplierProductHubsDocument } from '~/composables/graphql/public/geo-generated'
import { GetOffersBySupplierProductDocument, GetHubsNearOfferDocument } from '~/composables/graphql/public/geo-generated'
import {
GetSupplierProfileDocument,
GetSupplierOffersDocument,
GetSupplierProfilesDocument,
GetOffersDocument,
} from '~/composables/graphql/public/exchange-generated'
definePageMeta({
@@ -178,7 +176,7 @@ const chartSeries = computed(() => [{
// Load data
try {
// Get supplier
// Get supplier profile from exchange
const { data: supplierData } = await useServerQuery(
'supplier-profile',
GetSupplierProfileDocument,
@@ -200,66 +198,54 @@ try {
.find((s: any) => s?.teamUuid === supplierId.value || s?.uuid === supplierId.value) || null
}
// Get supplier's offers to find product and location
// Get offers for this supplier+product from geo
if (supplier.value) {
const teamIds = [supplier.value?.teamUuid, supplier.value?.uuid, supplierId.value].filter(Boolean)
const primaryId = teamIds[0] as string
const supplierUuidForGeo = supplier.value?.uuid || supplierId.value
const { data: offersData } = await useServerQuery(
'supplier-offers',
GetSupplierOffersDocument,
{ teamUuid: primaryId },
'public',
'exchange'
)
let offers = offersData.value?.getOffers || []
if (!offers.length) {
const { data: allOffersData } = await useServerQuery(
'supplier-offers-fallback',
GetOffersDocument,
{},
'public',
'exchange'
)
const ids = new Set(teamIds)
offers = (allOffersData.value?.getOffers || []).filter((o: any) => o?.teamUuid && ids.has(o.teamUuid))
}
// Find product in offers
for (const offer of offers) {
if (offer.productUuid === productId.value && offer.productName) {
product.value = { uuid: offer.productUuid, name: offer.productName }
if (offer.locationUuid && offer.locationName) {
sourceLocation.value = { uuid: offer.locationUuid, name: offer.locationName }
}
break
}
}
}
// Get hubs where this supplier can deliver this product
if (supplier.value && product.value) {
// Use supplier.uuid (public) for geo query, not teamUuid (internal)
const supplierUuidForGeo = supplier.value?.uuid || supplierId.value
const { data: hubsData } = await useServerQuery(
'supplier-product-hubs',
FindSupplierProductHubsDocument,
'supplier-product-offers',
GetOffersBySupplierProductDocument,
{ supplierUuid: supplierUuidForGeo, productUuid: productId.value },
'public',
'geo'
)
hubs.value = (hubsData.value?.findSupplierProductHubs || [])
.filter((h): h is NonNullable<typeof h> => h !== null && !!h.uuid && !!h.name)
.map(h => ({
uuid: h.uuid!,
name: h.name!,
latitude: h.latitude ?? undefined,
longitude: h.longitude ?? undefined,
country: h.country || undefined,
countryCode: h.countryCode || undefined
}))
const offers = offersData.value?.offersBySupplierProduct || []
// Set product info from first offer
if (offers.length > 0) {
const firstOffer = offers[0]
if (firstOffer?.productUuid && firstOffer?.productName) {
product.value = { uuid: firstOffer.productUuid, name: firstOffer.productName }
}
// Source location is the offer's location (first offer)
if (firstOffer?.latitude && firstOffer?.longitude) {
sourceLocation.value = {
uuid: firstOffer.uuid || '',
name: firstOffer.country || 'Origin'
}
}
// Get hubs near the first offer
const { data: hubsData } = await useServerQuery(
'hubs-near-offer',
GetHubsNearOfferDocument,
{ offerUuid: firstOffer.uuid, limit: 20 },
'public',
'geo'
)
hubs.value = (hubsData.value?.hubsNearOffer || [])
.filter((h): h is NonNullable<typeof h> => h !== null && !!h.uuid && !!h.name)
.map(h => ({
uuid: h.uuid!,
name: h.name!,
latitude: h.latitude ?? undefined,
longitude: h.longitude ?? undefined,
country: h.country || undefined,
countryCode: h.countryCode || undefined
}))
}
}
} catch (error) {
console.error('Error loading data:', error)

View File

@@ -1,11 +0,0 @@
query FindHubsForProduct($productUuid: String!) {
findHubsForProduct(productUuid: $productUuid) {
uuid
name
latitude
longitude
country
countryCode
transportTypes
}
}

View File

@@ -1,3 +0,0 @@
query FindProductsForHub($hubUuid: String!) {
findProductsForHub(hubUuid: $hubUuid)
}

View File

@@ -1,11 +0,0 @@
query FindSupplierProductHubs($supplierUuid: String!, $productUuid: String!) {
findSupplierProductHubs(supplierUuid: $supplierUuid, productUuid: $productUuid) {
uuid
name
latitude
longitude
country
countryCode
transportTypes
}
}

View File

@@ -1,9 +1,5 @@
query FindOffersForHubByProduct($hubUuid: String!, $productUuid: String!, $limitSources: Int) {
findOffersForHubByProduct(
hubUuid: $hubUuid
productUuid: $productUuid
limitSources: $limitSources
) {
query GetDeliveryToHub($offerUuid: String!, $hubUuid: String!) {
deliveryToHub(offerUuid: $offerUuid, hubUuid: $hubUuid) {
sourceUuid
sourceName
sourceLat

View File

@@ -0,0 +1,11 @@
query GetHubsNearOffer($offerUuid: String!, $limit: Int) {
hubsNearOffer(offerUuid: $offerUuid, limit: $limit) {
uuid
name
latitude
longitude
country
countryCode
transportTypes
}
}

View File

@@ -0,0 +1,16 @@
query GetOffersByProduct($productUuid: String!) {
offersByProduct(productUuid: $productUuid) {
uuid
productUuid
productName
supplierUuid
latitude
longitude
country
countryCode
pricePerUnit
currency
quantity
unit
}
}

View File

@@ -0,0 +1,16 @@
query GetOffersBySupplierProduct($supplierUuid: String!, $productUuid: String!) {
offersBySupplierProduct(supplierUuid: $supplierUuid, productUuid: $productUuid) {
uuid
productUuid
productName
supplierUuid
latitude
longitude
country
countryCode
pricePerUnit
currency
quantity
unit
}
}

View File

@@ -0,0 +1,26 @@
query GetOffersToHub($hubUuid: String!, $productUuid: String!, $limit: Int) {
offersToHub(hubUuid: $hubUuid, productUuid: $productUuid, limit: $limit) {
sourceUuid
sourceName
sourceLat
sourceLon
distanceKm
routes {
totalDistanceKm
totalTimeSeconds
stages {
fromUuid
fromName
fromLat
fromLon
toUuid
toName
toLat
toLon
distanceKm
travelTimeSeconds
transportType
}
}
}
}

View File

@@ -0,0 +1,6 @@
query GetProducts {
products {
uuid
name
}
}

View File

@@ -0,0 +1,6 @@
query GetProductsBySupplier($supplierUuid: String!) {
productsBySupplier(supplierUuid: $supplierUuid) {
uuid
name
}
}

View File

@@ -0,0 +1,6 @@
query GetProductsNearHub($hubUuid: String!, $radiusKm: Float) {
productsNearHub(hubUuid: $hubUuid, radiusKm: $radiusKm) {
uuid
name
}
}

View File

@@ -0,0 +1,5 @@
query GetSuppliers {
suppliers {
uuid
}
}