@@ -78,7 +78,7 @@ def get_watchlisted_tasks(cls, page, limit, user_id) -> Tuple[int, List[Watchlis
78
78
"$expr" : {
79
79
"$and" : [
80
80
{"$eq" : ["$task_id" , {"$toObjectId" : "$$taskIdStr" }]},
81
- {"$eq" : ["$is_active" , True ]}
81
+ {"$eq" : ["$is_active" , True ]},
82
82
]
83
83
}
84
84
}
@@ -97,7 +97,7 @@ def get_watchlisted_tasks(cls, page, limit, user_id) -> Tuple[int, List[Watchlis
97
97
"$expr" : {
98
98
"$and" : [
99
99
{"$eq" : ["$_id" , "$$assigneeId" ]},
100
- {"$eq" : [{"$arrayElemAt" : ["$assignment.user_type" , 0 ]}, "user" ]}
100
+ {"$eq" : [{"$arrayElemAt" : ["$assignment.user_type" , 0 ]}, "user" ]},
101
101
]
102
102
}
103
103
}
@@ -116,7 +116,7 @@ def get_watchlisted_tasks(cls, page, limit, user_id) -> Tuple[int, List[Watchlis
116
116
"$expr" : {
117
117
"$and" : [
118
118
{"$eq" : ["$_id" , "$$assigneeId" ]},
119
- {"$eq" : [{"$arrayElemAt" : ["$assignment.user_type" , 0 ]}, "team" ]}
119
+ {"$eq" : [{"$arrayElemAt" : ["$assignment.user_type" , 0 ]}, "team" ]},
120
120
]
121
121
}
122
122
}
@@ -137,24 +137,31 @@ def get_watchlisted_tasks(cls, page, limit, user_id) -> Tuple[int, List[Watchlis
137
137
"$cond" : {
138
138
"if" : {"$gt" : [{"$size" : "$assignee_user" }, 0 ]},
139
139
"then" : {
140
- "assignee_id" : {"$toString" : {"$arrayElemAt" : ["$assignee_user._id" , 0 ]}},
140
+ "assignee_id" : {
141
+ "$toString" : {"$arrayElemAt" : ["$assignee_user._id" , 0 ]}
142
+ },
141
143
"assignee_name" : {"$arrayElemAt" : ["$assignee_user.name" , 0 ]},
142
- "user_type" : "user"
144
+ "user_type" : "user" ,
143
145
},
144
146
"else" : {
145
147
"$cond" : {
146
148
"if" : {"$gt" : [{"$size" : "$assignee_team" }, 0 ]},
147
149
"then" : {
148
- "id" : {"$toString" : {"$arrayElemAt" : ["$assignee_team._id" , 0 ]}},
149
- "name" : {"$arrayElemAt" : ["$assignee_team.name" , 0 ]},
150
- "email" : {"$concat" : [{"$arrayElemAt" : ["$assignee_team.name" , 0 ]}, "@team" ]},
151
- "type" : "team"
150
+ "assignee_id" : {
151
+ "$toString" : {
152
+ "$arrayElemAt" : ["$assignee_team._id" , 0 ]
153
+ }
154
+ },
155
+ "assignee_name" : {
156
+ "$arrayElemAt" : ["$assignee_team.name" , 0 ]
157
+ },
158
+ "user_type" : "team" ,
152
159
},
153
- "else" : None
160
+ "else" : None ,
154
161
}
155
- }
162
+ },
156
163
}
157
- }
164
+ },
158
165
},
159
166
]
160
167
}
@@ -174,7 +181,7 @@ def get_watchlisted_tasks(cls, page, limit, user_id) -> Tuple[int, List[Watchlis
174
181
count = result .get ("total" , 0 )
175
182
176
183
tasks = [_convert_objectids_to_str (doc ) for doc in result .get ("data" , [])]
177
-
184
+
178
185
# If assignee is null, try to fetch it separately
179
186
for task in tasks :
180
187
if not task .get ("assignee" ):
@@ -191,43 +198,35 @@ def _get_assignee_for_task(cls, task_id: str):
191
198
"""
192
199
if not task_id :
193
200
return None
194
-
201
+
195
202
try :
196
203
from todo .repositories .task_assignment_repository import TaskAssignmentRepository
197
204
from todo .repositories .user_repository import UserRepository
198
205
from todo .repositories .team_repository import TeamRepository
199
-
206
+
200
207
# Get task assignment
201
208
assignment = TaskAssignmentRepository .get_by_task_id (task_id )
202
209
if not assignment :
203
210
return None
204
-
211
+
205
212
assignee_id = str (assignment .assignee_id )
206
213
user_type = assignment .user_type
207
-
214
+
208
215
if user_type == "user" :
209
216
# Get user details
210
217
user = UserRepository .get_by_id (assignee_id )
211
218
if user :
212
- return {
213
- "assignee_id" : assignee_id ,
214
- "assignee_name" : user .name ,
215
- "user_type" : "user"
216
- }
219
+ return {"assignee_id" : assignee_id , "assignee_name" : user .name , "user_type" : "user" }
217
220
elif user_type == "team" :
218
221
# Get team details
219
222
team = TeamRepository .get_by_id (assignee_id )
220
223
if team :
221
- return {
222
- "assignee_id" : assignee_id ,
223
- "assignee_name" : team .name ,
224
- "user_type" : "team"
225
- }
226
-
224
+ return {"assignee_id" : assignee_id , "assignee_name" : team .name , "user_type" : "team" }
225
+
227
226
except Exception :
228
227
# If any error occurs, return None
229
228
return None
230
-
229
+
231
230
return None
232
231
233
232
@classmethod
0 commit comments