Fix supplier query - aggregate through offers
All checks were successful
Build Docker Image / build (push) Successful in 1m21s

Only show suppliers that have active offers.
This commit is contained in:
Ruslan Bakiev
2026-01-23 11:23:54 +07:00
parent 0106c84daf
commit 3a24f4a9cd

View File

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