Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 31 additions & 7 deletions todo/repositories/task_repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,10 @@ def list(

if team_id:
logger.debug(f"TaskRepository.list: team_id={team_id}")
team_assignments = TaskAssignmentRepository.get_by_assignee_id(team_id, "team")
team_task_ids = [assignment.task_id for assignment in team_assignments]
logger.debug(f"TaskRepository.list: team_task_ids={team_task_ids}")
query_filter = {"$and": [base_filter, {"_id": {"$in": team_task_ids}}]}

all_task_object_ids = cls._get_team_task_ids(team_id)

query_filter = {"$and": [base_filter, {"_id": {"$in": all_task_object_ids}}]}
logger.debug(f"TaskRepository.list: query_filter={query_filter}")
elif user_id:
assigned_task_ids = cls._get_assigned_task_ids_for_user(user_id)
Expand Down Expand Up @@ -101,16 +101,40 @@ def _get_assigned_task_ids_for_user(cls, user_id: str) -> List[ObjectId]:

return direct_task_ids + team_task_ids

@classmethod
def _get_team_task_ids(cls, team_id: str) -> List[ObjectId]:
"""Get task IDs for a team (both team assignments and member assignments)."""
from todo.repositories.team_repository import UserTeamDetailsRepository
from bson import ObjectId

team_members = UserTeamDetailsRepository.get_users_by_team_id(team_id)

pipeline = [
{
"$match": {
"$or": [
{"assignee_id": team_id, "user_type": "team", "is_active": True},
{"assignee_id": {"$in": team_members}, "user_type": "user", "is_active": True},
]
}
},
{"$project": {"task_id": 1}},
]

assignments = TaskAssignmentRepository.get_collection().aggregate(pipeline)
all_task_ids = [assignment["task_id"] for assignment in assignments]

return [ObjectId(task_id) for task_id in all_task_ids]

@classmethod
def count(cls, user_id: str = None, team_id: str = None, status_filter: str = None) -> int:
tasks_collection = cls.get_collection()

base_filter = cls._build_status_filter(status_filter)

if team_id:
team_assignments = TaskAssignmentRepository.get_by_assignee_id(team_id, "team")
team_task_ids = [assignment.task_id for assignment in team_assignments]
query_filter = {"$and": [base_filter, {"_id": {"$in": team_task_ids}}]}
all_task_object_ids = cls._get_team_task_ids(team_id)
query_filter = {"$and": [base_filter, {"_id": {"$in": all_task_object_ids}}]}
elif user_id:
assigned_task_ids = cls._get_assigned_task_ids_for_user(user_id)
query_filter = {
Expand Down