Skip to content

Commit

Permalink
mongo.fix: return new department document in case not found
Browse files Browse the repository at this point in the history
  • Loading branch information
furkansimsekli committed Dec 13, 2023
1 parent 77fce7f commit c8132c9
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/mongo.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,18 @@ def __fetch_collection(self) -> AsyncIOMotorClient:
collection = db['departments']
return collection

async def find(self, department_id: str) -> list[dict]:
async def find(self, department_id: str) -> dict:
collection = self.__fetch_collection()
document = await collection.find_one({'department_id': department_id})

if not document:
await collection.insert_one({
document = {
'department_id': department_id,
'announcement_list': [],
'is_active': True
})
return []
}
await collection.insert_one(document)
return document

return document

Expand Down

0 comments on commit c8132c9

Please sign in to comment.