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:
@@ -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