diff --git a/util/get_class.py b/util/get_class.py index 630787d..f4f8bf7 100644 --- a/util/get_class.py +++ b/util/get_class.py @@ -3,9 +3,7 @@ from utils import validate_object_id -async def get_activities_related_to_user( - user_oid: str, page: int = -1, perpage: int = 10, query: str = "", target: str = '' -): +async def get_user_class(user_oid: str) -> str: user = await db.zvms.users.find_one({"_id": validate_object_id(user_oid)}) if not user: raise HTTPException(status_code=404, detail="User not found") @@ -28,7 +26,17 @@ async def get_activities_related_to_user( if not class_id: raise HTTPException(status_code=404, detail="User not in any class") - users = await db.zvms.users.find({"group": str(class_id)}).to_list(None) + return class_id + + +async def get_activities_related_to_user( + user_oid: str, page: int = -1, perpage: int = 10, query: str = "", target: str = '' +): + + if not target: + target = await get_user_class(user_oid) + + users = await db.zvms.users.find({"group": str(target)}).to_list(None) count = await db.zvms.activities.count_documents( {