Skip to content

Commit fc31c17

Browse files
feat: add recent activity sort for watchlist task (#251)
1 parent ac46028 commit fc31c17

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

todo/repositories/watchlist_repository.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,26 @@ def get_watchlisted_tasks(cls, page, limit, user_id) -> Tuple[int, List[Watchlis
6868
}
6969
},
7070
{"$unwind": "$task"},
71+
{
72+
"$addFields": {
73+
"lastAdded": {"$ifNull": [{"$toDate": "$updatedAt"}, {"$toDate": "$createdAt"}]},
74+
"lastActivity": {
75+
"$ifNull": [{"$toDate": "$task.updatedAt"}, {"$toDate": "$task.createdAt"}]
76+
},
77+
}
78+
},
79+
{
80+
"$addFields": {
81+
"lastEvent": {
82+
"$cond": {
83+
"if": {"$gt": ["$lastAdded", "$lastActivity"]},
84+
"then": "$lastAdded",
85+
"else": "$lastActivity",
86+
}
87+
}
88+
}
89+
},
90+
{"$sort": {"lastEvent": -1}},
7191
{
7292
"$lookup": {
7393
"from": "users",

0 commit comments

Comments
 (0)