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()]
예제 #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)
예제 #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)
예제 #6
0
 def delete(self, id: UUID) -> None:
     db.collection(self.collection_name).document(str(id)).delete()
예제 #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)
예제 #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()]
예제 #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)