From 2fb34f664f46112e276b06fca3eedb88943bb7ea Mon Sep 17 00:00:00 2001 From: Ruslan Bakiev <572431+veikab@users.noreply.github.com> Date: Sat, 7 Feb 2026 11:06:00 +0700 Subject: [PATCH] Use graph-based offers and remove radius filters --- app/composables/useCatalogHubs.ts | 4 +- app/composables/useCatalogInfo.ts | 34 +++++++------- app/composables/useCatalogProducts.ts | 61 +++++++++----------------- app/composables/useCatalogSuppliers.ts | 4 +- app/pages/catalog/index.vue | 2 - 5 files changed, 38 insertions(+), 67 deletions(-) diff --git a/app/composables/useCatalogHubs.ts b/app/composables/useCatalogHubs.ts index 12139cc..8a2a35b 100644 --- a/app/composables/useCatalogHubs.ts +++ b/app/composables/useCatalogHubs.ts @@ -61,15 +61,13 @@ export function useCatalogHubs() { const fetchPage = async (offset: number, replace = false) => { if (replace) isLoading.value = true try { - // If filtering by product, use nearestHubs with global search - // (center point 0,0 with very large radius to cover entire globe) + // If filtering by product, use nearestHubs (graph-based) if (filterProductUuid.value) { const data = await execute( NearestHubsDocument, { lat: 0, lon: 0, - radius: 20000, // 20000 km radius covers entire Earth productUuid: filterProductUuid.value, useGraph: true, limit: 500 // Increased limit for global search diff --git a/app/composables/useCatalogInfo.ts b/app/composables/useCatalogInfo.ts index 7ae6d1b..30d57db 100644 --- a/app/composables/useCatalogInfo.ts +++ b/app/composables/useCatalogInfo.ts @@ -15,7 +15,8 @@ import type { } from '~/composables/graphql/public/exchange-generated' import { GetOfferDocument, - GetSupplierProfileDocument + GetSupplierProfileDocument, + GetSupplierOffersDocument } from '~/composables/graphql/public/exchange-generated' // Types from codegen @@ -125,7 +126,8 @@ export function useCatalogInfo() { { lat: coords.lat, lon: coords.lon, - radius: 500 + hubUuid: uuid, + limit: 500 }, 'public', 'geo' @@ -224,21 +226,16 @@ export function useCatalogInfo() { isLoadingProducts.value = true isLoadingHubs.value = true - // Load products (offers grouped by product) + // Load products from supplier offers (no geo radius) execute( - NearestOffersDocument, - { - lat: entity.value.latitude, - lon: entity.value.longitude, - radius: 500 - }, + GetSupplierOffersDocument, + { teamUuid: uuid }, 'public', - 'geo' + 'exchange' ).then(offersData => { - // Group offers by product const productsMap = new Map() - offersData?.nearestOffers?.forEach(offer => { - if (!offer || !offer.productUuid || !offer.productName) return + offersData?.getOffers?.forEach(offer => { + if (!offer?.productUuid || !offer.productName) return const existing = productsMap.get(offer.productUuid) if (existing) { existing.offersCount = (existing.offersCount || 0) + 1 @@ -261,7 +258,6 @@ export function useCatalogInfo() { { lat: entity.value.latitude, lon: entity.value.longitude, - radius: 1000, sourceUuid: entity.value.uuid, limit: 12 }, @@ -312,7 +308,6 @@ export function useCatalogInfo() { { lat: coords.lat, lon: coords.lon, - radius: 1000, sourceUuid: entity.value?.uuid ?? null, limit: 12 }, @@ -372,7 +367,6 @@ export function useCatalogInfo() { lon: hub.longitude, productUuid, hubUuid, // Pass hubUuid to get routes calculated on backend - radius: 500, limit: 12 }, 'public', @@ -438,7 +432,6 @@ export function useCatalogInfo() { { lat: supplier.latitude, lon: supplier.longitude, - radius: 1000, sourceUuid: supplier.uuid, limit: 1 }, @@ -462,14 +455,17 @@ export function useCatalogInfo() { lon: supplier.longitude, productUuid, ...(hubUuid ? { hubUuid } : {}), - radius: 500, limit: 12 }, 'public', 'geo' ) - relatedOffers.value = (offersData?.nearestOffers || []).filter((o): o is OfferItem => o !== null) + relatedOffers.value = (offersData?.nearestOffers || []).filter((o): o is OfferItem => { + if (!o) return false + if (!supplier.uuid) return true + return o.supplierUuid === supplier.uuid + }) isLoadingOffers.value = false } finally { isLoadingOffers.value = false diff --git a/app/composables/useCatalogProducts.ts b/app/composables/useCatalogProducts.ts index a7afdae..7255a07 100644 --- a/app/composables/useCatalogProducts.ts +++ b/app/composables/useCatalogProducts.ts @@ -5,7 +5,7 @@ import { NearestOffersDocument } from '~/composables/graphql/public/geo-generated' import { - GetSupplierProfileDocument + GetSupplierOffersDocument } from '~/composables/graphql/public/exchange-generated' // Type from codegen @@ -43,46 +43,26 @@ export function useCatalogProducts() { let data if (filterSupplierUuid.value) { - // Products from specific supplier - get supplier coordinates first - const supplierData = await execute( - GetSupplierProfileDocument, - { uuid: filterSupplierUuid.value }, + // Products from specific supplier - get offers directly (no geo radius) + const offersData = await execute( + GetSupplierOffersDocument, + { teamUuid: filterSupplierUuid.value }, 'public', 'exchange' ) - const supplier = supplierData?.getSupplierProfile - - if (!supplier?.latitude || !supplier?.longitude) { - console.warn('Supplier has no coordinates') - items.value = [] - } else { - // Get offers near supplier and group by product - const offersData = await execute( - NearestOffersDocument, - { - lat: supplier.latitude, - lon: supplier.longitude, - radius: 500 - }, - 'public', - 'geo' - ) - - // Group offers by product - const productsMap = new Map() - offersData?.nearestOffers?.forEach((offer) => { - if (!offer?.productUuid) return - if (!productsMap.has(offer.productUuid)) { - productsMap.set(offer.productUuid, { - uuid: offer.productUuid, - name: offer.productName, - offersCount: 0 - }) - } - productsMap.get(offer.productUuid)!.offersCount++ - }) - items.value = Array.from(productsMap.values()) as ProductItem[] - } + const productsMap = new Map() + offersData?.getOffers?.forEach((offer) => { + if (!offer?.productUuid) return + if (!productsMap.has(offer.productUuid)) { + productsMap.set(offer.productUuid, { + uuid: offer.productUuid, + name: offer.productName, + offersCount: 0 + }) + } + productsMap.get(offer.productUuid)!.offersCount++ + }) + items.value = Array.from(productsMap.values()) as ProductItem[] } else if (filterHubUuid.value) { // Products near hub - get hub coordinates first const hubData = await execute( @@ -97,13 +77,14 @@ export function useCatalogProducts() { console.warn('Hub has no coordinates') items.value = [] } else { - // Get offers near hub and group by product + // Get offers by graph from hub and group by product const offersData = await execute( NearestOffersDocument, { lat: hub.latitude, lon: hub.longitude, - radius: 500 + hubUuid: filterHubUuid.value, + limit: 500 }, 'public', 'geo' diff --git a/app/composables/useCatalogSuppliers.ts b/app/composables/useCatalogSuppliers.ts index 1c1c9ba..9df5a5e 100644 --- a/app/composables/useCatalogSuppliers.ts +++ b/app/composables/useCatalogSuppliers.ts @@ -28,15 +28,13 @@ export function useCatalogSuppliers() { const fetchPage = async (offset: number, replace = false) => { if (replace) isLoading.value = true try { - // If filtering by product, use nearestSuppliers with global search - // (center point 0,0 with very large radius to cover entire globe) + // If filtering by product, use nearestSuppliers (product-only list) if (filterProductUuid.value) { const data = await execute( NearestSuppliersDocument, { lat: 0, lon: 0, - radius: 20000, // 20000 km radius covers entire Earth productUuid: filterProductUuid.value, limit: 500 // Increased limit for global search }, diff --git a/app/pages/catalog/index.vue b/app/pages/catalog/index.vue index b728549..c15ced1 100644 --- a/app/pages/catalog/index.vue +++ b/app/pages/catalog/index.vue @@ -657,7 +657,6 @@ const onSearch = async () => { productUuid: productId.value, hubUuid: hubId.value, quantity: quantity.value ? Number(quantity.value) : null, - radius: 500, limit: 10 }, 'public', @@ -682,7 +681,6 @@ const onSearch = async () => { lon: hub.longitude, productUuid: productId.value, hubUuid: hubId.value, - radius: 500, limit: 12 }, 'public',