From 3a24f4a9cd8d759331b13eba680b123911a76f44 Mon Sep 17 00:00:00 2001 From: Ruslan Bakiev <572431+veikab@users.noreply.github.com> Date: Fri, 23 Jan 2026 11:23:54 +0700 Subject: [PATCH] Fix supplier query - aggregate through offers Only show suppliers that have active offers. --- geo_app/cluster_index.py | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/geo_app/cluster_index.py b/geo_app/cluster_index.py index 3153e27..10a9ce6 100644 --- a/geo_app/cluster_index.py +++ b/geo_app/cluster_index.py @@ -43,11 +43,26 @@ def _fetch_nodes(db, transport_type=None, node_type=None): RETURN node """ elif node_type == 'supplier': + # Get suppliers that have offers (aggregate through offers) aql = """ - FOR node IN nodes - FILTER node.node_type == 'supplier' - FILTER node.latitude != null AND node.longitude != null - RETURN node + FOR offer IN nodes + FILTER offer.node_type == 'offer' + FILTER offer.supplier_uuid != null + LET supplier = DOCUMENT(CONCAT('nodes/', offer.supplier_uuid)) + FILTER supplier != null + FILTER supplier.latitude != null AND supplier.longitude != null + COLLECT sup_uuid = offer.supplier_uuid INTO offers + LET sup = DOCUMENT(CONCAT('nodes/', sup_uuid)) + RETURN { + _key: sup_uuid, + name: sup.name, + latitude: sup.latitude, + longitude: sup.longitude, + country: sup.country, + country_code: sup.country_code, + node_type: 'supplier', + offers_count: LENGTH(offers) + } """ else: # logistics (default) aql = """