Update user repository implementation.

This commit is contained in:
xds
2026-02-09 16:16:55 +03:00
parent 458b6ebfc3
commit a9d24c725e
2 changed files with 6 additions and 3 deletions

View File

@@ -20,12 +20,14 @@ class UsersRepo:
async def get_user(self, user_id: int): async def get_user(self, user_id: int):
user = await self.collection.find_one({"user_id": user_id}) user = await self.collection.find_one({"user_id": user_id})
user["id"] = str(user["_id"]) if user:
user["id"] = str(user["_id"])
return user return user
async def get_user_by_username(self, username: str): async def get_user_by_username(self, username: str):
user = await self.collection.find_one({"username": username}) user = await self.collection.find_one({"username": username})
user["id"] = str(user["_id"]) if user:
user["id"] = str(user["_id"])
return user return user
async def create_user(self, username: str, password: str, full_name: Optional[str] = None): async def create_user(self, username: str, password: str, full_name: Optional[str] = None):
@@ -48,7 +50,8 @@ class UsersRepo:
} }
result = await self.collection.insert_one(user_doc) result = await self.collection.insert_one(user_doc)
user = await self.collection.find_one({"_id": result.inserted_id}) user = await self.collection.find_one({"_id": result.inserted_id})
user["id"] = str(user["_id"]) if user:
user["id"] = str(user["_id"])
return user return user
async def get_pending_users(self): async def get_pending_users(self):