def get_by_account_id(self, account_id: str, parent: str = None) -> List[Transaction]:
        coll_ref = self.collection_ref
        if parent:
            coll_ref = db.collection(parent + '/' + self.collection_name)

        transactions = coll_ref.where('account_id', '==', account_id).stream()
        return [Transaction(**doc.to_dict()) for doc in transactions if doc.to_dict()]
Exemplo n.º 2
0
    def get(self, id: UUID) -> Todo:
        doc_ref = db.collection(self.collection_name).document(str(id))
        doc = doc_ref.get()

        if doc.exists:
            return Todo(**doc.to_dict())

        return None
 def __init__(self):
     self.collection_ref = db.collection(self.collection_name)
Exemplo n.º 4
0
 def get_client_ref(self, client_id: str):
     return db.collection(self.clients_collection).document(client_id)
 def __init__(self, parent=None):
     self.collection_ref = db.collection(self.collection_name)
Exemplo n.º 6
0
 def delete(self, id: UUID) -> None:
     db.collection(self.collection_name).document(str(id)).delete()
Exemplo n.º 7
0
 def update(self, id: UUID, todo_update: TodoUpdate) -> Todo:
     data = todo_update.dict()
     doc_ref = db.collection(self.collection_name).document(str(id))
     doc_ref.update(data)
     return self.get(id)
Exemplo n.º 8
0
 def list(self) -> List[Todo]:
     todos_ref = db.collection(self.collection_name)
     return [Todo(**doc.get().to_dict()) for doc in todos_ref.list_documents() if doc.get().to_dict()]
Exemplo n.º 9
0
 def create(self, todo_create: TodoCreate) -> Todo:
     data = todo_create.dict()
     data['id'] = str(data['id'])
     doc_ref = db.collection(self.collection_name).document(str(todo_create.id))
     doc_ref.set(data)
     return self.get(todo_create.id)