File tree Expand file tree Collapse file tree 1 file changed +42
-0
lines changed
Expand file tree Collapse file tree 1 file changed +42
-0
lines changed Original file line number Diff line number Diff line change @@ -60,6 +60,48 @@ export default {
6060 . skip ( offset )
6161 . limit ( pageSize ) ;
6262 }
63+ if ( type === 'HOT' ) {
64+ const oneWeekAgo = new Date ( ) ;
65+ period = { $gte : 19 } ;
66+ sort = { } ;
67+ const schemaProps = Object . keys ( ProcedureModel . schema . obj ) . reduce (
68+ ( obj , prop ) => ( { ...obj , [ prop ] : { $first : `$${ prop } ` } } ) ,
69+ { } ,
70+ ) ;
71+ const hotProcedures = await ProcedureModel . aggregate ( [
72+ {
73+ $match : {
74+ period,
75+ $or : [
76+ { voteDate : { $gt : oneWeekAgo . setDate ( oneWeekAgo . getDate ( ) - 7 ) } } ,
77+ { voteDate : null } ,
78+ ] ,
79+ } ,
80+ } ,
81+ {
82+ $lookup : {
83+ from : 'activities' ,
84+ localField : '_id' ,
85+ foreignField : 'procedure' ,
86+ as : 'activityIndex' ,
87+ } ,
88+ } ,
89+ { $unwind : '$activityIndex' } ,
90+ {
91+ $group : {
92+ _id : '$_id' ,
93+ ...schemaProps ,
94+ activities : { $sum : 1 } ,
95+ } ,
96+ } ,
97+ { $sort : { activities : - 1 } } ,
98+
99+ { $skip : offset } ,
100+ { $limit : pageSize } ,
101+ ] ) ;
102+
103+ return hotProcedures ;
104+ }
63105
64106 const activeVotings = await ProcedureModel . find ( {
65107 voteDate : { $exists : false } ,
You can’t perform that action at this time.
0 commit comments