Skip to content

Commit

Permalink
fix: should not return self class activities if class is specified.
Browse files Browse the repository at this point in the history
  • Loading branch information
7086cmd committed Sep 28, 2024
1 parent ef6152a commit 8380a13
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions util/get_class.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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(
{
Expand Down

0 comments on commit 8380a13

Please sign in to comment.