Explorar o código

add countLikers method

takeru0001 %!s(int64=5) %!d(string=hai) anos
pai
achega
008fbb3200
Modificáronse 1 ficheiros con 8 adicións e 0 borrados
  1. 8 0
      src/server/models/page.js

+ 8 - 0
src/server/models/page.js

@@ -389,6 +389,14 @@ module.exports = function(crowi) {
     }));
     }));
   };
   };
 
 
+  pageSchema.statics.countLikers = async function(pageId) {
+    const result = this.aggregate()
+      .match({ page: { $in: pageId } })
+      .group({ _id: '$page', count: { $sum: 1 } });
+
+    return result;
+  };
+
   pageSchema.methods.isSeenUser = function(userData) {
   pageSchema.methods.isSeenUser = function(userData) {
     return this.seenUsers.includes(userData._id);
     return this.seenUsers.includes(userData._id);
   };
   };