Spaces:
Sleeping
Sleeping
Update data_fetcher.py
Browse files- data_fetcher.py +13 -4
data_fetcher.py
CHANGED
|
@@ -37,10 +37,19 @@ def fetch_data_from_firestore(instruction):
|
|
| 37 |
limit = col.get("limit", 50)
|
| 38 |
|
| 39 |
try:
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 44 |
except Exception as e:
|
| 45 |
results[name] = {"error": str(e)}
|
| 46 |
|
|
|
|
| 37 |
limit = col.get("limit", 50)
|
| 38 |
|
| 39 |
try:
|
| 40 |
+
if name == "users" and any(f["field"] == "uid" for f in filters):
|
| 41 |
+
uid_filter = next(f for f in filters if f["field"] == "uid")
|
| 42 |
+
doc_id = uid_filter["value"]
|
| 43 |
+
doc = db.collection("users").document(doc_id).get()
|
| 44 |
+
if doc.exists:
|
| 45 |
+
results[name] = [doc.to_dict()]
|
| 46 |
+
else:
|
| 47 |
+
results[name] = []
|
| 48 |
+
else:
|
| 49 |
+
col_ref = db.collection(name)
|
| 50 |
+
col_ref = apply_filters(col_ref, filters)
|
| 51 |
+
docs = col_ref.limit(limit).stream()
|
| 52 |
+
results[name] = [doc.to_dict() for doc in docs]
|
| 53 |
except Exception as e:
|
| 54 |
results[name] = {"error": str(e)}
|
| 55 |
|