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 = """