feat: use filtered geo queries for catalog pages
All checks were successful
Build Docker Image / build (push) Successful in 4m57s
All checks were successful
Build Docker Image / build (push) Successful in 4m57s
- /hubs/[id]: use findProductsForHub to show only deliverable products - /offers/[productId]: use findHubsForProduct to show only reachable hubs - /suppliers/[id]/[productId]: use findSupplierProductHubs for supplier-specific hubs - Add new GraphQL operations for geo queries
This commit is contained in:
@@ -58,7 +58,7 @@
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { GetNodeConnectionsDocument } from '~/composables/graphql/public/geo-generated'
|
||||
import { GetNodeConnectionsDocument, FindProductsForHubDocument } from '~/composables/graphql/public/geo-generated'
|
||||
import { GetAvailableProductsDocument } from '~/composables/graphql/public/exchange-generated'
|
||||
|
||||
definePageMeta({
|
||||
@@ -92,14 +92,18 @@ const getMockPriceHistory = (uuid: string): number[] => {
|
||||
|
||||
// Initial load
|
||||
try {
|
||||
const [{ data: connectionsData }, { data: productsData }] = await Promise.all([
|
||||
const [{ data: connectionsData }, { data: productUuidsData }, { data: allProductsData }] = 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')
|
||||
])
|
||||
|
||||
hub.value = connectionsData.value?.nodeConnections?.hub || null
|
||||
products.value = (productsData.value?.getAvailableProducts || [])
|
||||
.filter((p): p is { uuid: string; name: string } => p !== null && !!p.uuid && !!p.name)
|
||||
|
||||
// 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! }))
|
||||
} catch (error) {
|
||||
console.error('Error loading hub:', error)
|
||||
|
||||
@@ -72,7 +72,7 @@
|
||||
|
||||
<script setup lang="ts">
|
||||
import { GetAvailableProductsDocument } from '~/composables/graphql/public/exchange-generated'
|
||||
import { GetNodesDocument } from '~/composables/graphql/public/geo-generated'
|
||||
import { FindHubsForProductDocument } from '~/composables/graphql/public/geo-generated'
|
||||
|
||||
definePageMeta({
|
||||
layout: 'topnav'
|
||||
@@ -133,7 +133,7 @@ const chartSeries = computed(() => [{
|
||||
try {
|
||||
const [{ data: productsData }, { data: hubsData }] = await Promise.all([
|
||||
useServerQuery('product-info', GetAvailableProductsDocument, {}, 'public', 'exchange'),
|
||||
useServerQuery('all-hubs', GetNodesDocument, { limit: 100 }, 'public', 'geo')
|
||||
useServerQuery('hubs-for-product', FindHubsForProductDocument, { productUuid: productId.value }, 'public', 'geo')
|
||||
])
|
||||
|
||||
const foundProduct = (productsData.value?.getAvailableProducts || [])
|
||||
@@ -143,7 +143,8 @@ try {
|
||||
product.value = { uuid: foundProduct.uuid!, name: foundProduct.name || '' }
|
||||
}
|
||||
|
||||
hubs.value = (hubsData.value?.nodes || [])
|
||||
// Get only hubs where this product can be delivered
|
||||
hubs.value = (hubsData.value?.findHubsForProduct || [])
|
||||
.filter((h): h is { uuid: string; name: string; country?: string; countryCode?: string } =>
|
||||
h !== null && !!h.uuid && !!h.name
|
||||
)
|
||||
|
||||
@@ -86,7 +86,7 @@
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { GetNodesDocument } from '~/composables/graphql/public/geo-generated'
|
||||
import { FindSupplierProductHubsDocument } from '~/composables/graphql/public/geo-generated'
|
||||
import {
|
||||
GetSupplierProfileDocument,
|
||||
GetSupplierOffersDocument,
|
||||
@@ -215,20 +215,23 @@ try {
|
||||
}
|
||||
}
|
||||
|
||||
// Get hubs (destinations)
|
||||
const { data: hubsData } = await useServerQuery(
|
||||
'all-hubs',
|
||||
GetNodesDocument,
|
||||
{ limit: 100 },
|
||||
'public',
|
||||
'geo'
|
||||
)
|
||||
|
||||
hubs.value = (hubsData.value?.nodes || [])
|
||||
.filter((h): h is { uuid: string; name: string; country?: string; countryCode?: string } =>
|
||||
h !== null && !!h.uuid && !!h.name
|
||||
// Get hubs where this supplier can deliver this product
|
||||
if (supplier.value && product.value) {
|
||||
const supplierUuidForGeo = supplier.value?.teamUuid || supplier.value?.uuid || supplierId.value
|
||||
const { data: hubsData } = await useServerQuery(
|
||||
'supplier-product-hubs',
|
||||
FindSupplierProductHubsDocument,
|
||||
{ supplierUuid: supplierUuidForGeo, productUuid: productId.value },
|
||||
'public',
|
||||
'geo'
|
||||
)
|
||||
.map(h => ({ uuid: h.uuid!, name: h.name!, country: h.country || undefined, countryCode: h.countryCode || undefined }))
|
||||
|
||||
hubs.value = (hubsData.value?.findSupplierProductHubs || [])
|
||||
.filter((h): h is { uuid: string; name: string; country?: string; countryCode?: string } =>
|
||||
h !== null && !!h.uuid && !!h.name
|
||||
)
|
||||
.map(h => ({ uuid: h.uuid!, name: h.name!, country: h.country || undefined, countryCode: h.countryCode || undefined }))
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Error loading data:', error)
|
||||
} finally {
|
||||
|
||||
Reference in New Issue
Block a user