forked from BasedHardware/omi
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtasks.py
More file actions
30 lines (21 loc) · 838 Bytes
/
Copy pathtasks.py
File metadata and controls
30 lines (21 loc) · 838 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
from typing import Any
from google.cloud.firestore_v1 import FieldFilter
from ._client import db
def create(task_data: dict[str, Any]) -> None:
task_id = task_data['id']
task_ref = db.collection('tasks').document(task_id)
task_ref.set(task_data)
def update(task_id: str, task_data: dict[str, Any]) -> None:
task_ref = db.collection('tasks').document(task_id)
task_ref.update(task_data)
def get_task_by_action_request(action: str, request_id: str) -> dict[str, Any] | None:
query = (
db.collection('tasks')
.where(filter=FieldFilter('action', '==', action))
.where(filter=FieldFilter('request_id', '==', request_id))
.limit(1)
)
tasks: list[dict[str, Any]] = [item.to_dict() for item in query.stream()]
if len(tasks) > 0:
return tasks[0]
return None