takeru0001 před 5 roky
rodič
revize
1e8f61d69a
1 změnil soubory, kde provedl 15 přidání a 1 odebrání
  1. 15 1
      src/server/routes/apiv3/page.js

+ 15 - 1
src/server/routes/apiv3/page.js

@@ -117,7 +117,7 @@ module.exports = (crowi) => {
   const apiV3FormValidator = require('../../middlewares/apiv3-form-validator')(crowi);
 
   const globalNotificationService = crowi.getGlobalNotificationService();
-  const { Page, GlobalNotificationSetting } = crowi.models;
+  const { Page, GlobalNotificationSetting, User } = crowi.models;
   const { exportService } = crowi;
 
   const validator = {
@@ -196,6 +196,20 @@ module.exports = (crowi) => {
     return res.apiv3({ result });
   });
 
+  router.get('/likeInfo', async(req, res) => {
+    const pageId = req.query._id;
+    const likeInfo = {};
+    try {
+      likeInfo.users = await Page.findById(pageId).populate('liker', User.USER_PUBLIC_FIELDS);
+      likeInfo.sumOfLikers = likeInfo.users.liker.length;
+
+      return res.apiv3({ likeInfo });
+    }
+    catch (err) {
+      logger.error('error like info', err);
+    }
+  });
+
   /**
   * @swagger
   *