Update catalog pages to use new geo queries
Some checks failed
Build Docker Image / build (push) Failing after 1m35s
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:
@@ -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
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user