Yuki Takei 4 лет назад
Родитель
Сommit
f460b0bc07
1 измененных файлов с 14 добавлено и 11 удалено
  1. 14 11
      packages/app/src/server/routes/apiv3/page.js

+ 14 - 11
packages/app/src/server/routes/apiv3/page.js

@@ -185,7 +185,7 @@ module.exports = (crowi) => {
    *                  $ref: '#/components/schemas/Page'
    *                  $ref: '#/components/schemas/Page'
    */
    */
   router.put('/likes', accessTokenParser, loginRequiredStrictly, csrf, validator.likes, apiV3FormValidator, async(req, res) => {
   router.put('/likes', accessTokenParser, loginRequiredStrictly, csrf, validator.likes, apiV3FormValidator, async(req, res) => {
-    const { pageId, bool } = req.body;
+    const { pageId, bool: isLiked } = req.body;
 
 
     let page;
     let page;
     try {
     try {
@@ -193,7 +193,8 @@ module.exports = (crowi) => {
       if (page == null) {
       if (page == null) {
         return res.apiv3Err(`Page '${pageId}' is not found or forbidden`);
         return res.apiv3Err(`Page '${pageId}' is not found or forbidden`);
       }
       }
-      if (bool) {
+
+      if (isLiked) {
         page = await page.like(req.user);
         page = await page.like(req.user);
       }
       }
       else {
       else {
@@ -205,17 +206,19 @@ module.exports = (crowi) => {
       return res.apiv3Err(err, 500);
       return res.apiv3Err(err, 500);
     }
     }
 
 
-    try {
-      // global notification
-      await globalNotificationService.fire(GlobalNotificationSetting.EVENT.PAGE_LIKE, page, req.user);
-    }
-    catch (err) {
-      logger.error('Like notification failed', err);
-    }
-
     const result = { page };
     const result = { page };
     result.seenUser = page.seenUsers;
     result.seenUser = page.seenUsers;
-    return res.apiv3({ result });
+    res.apiv3({ result });
+
+    if (isLiked) {
+      try {
+        // global notification
+        await globalNotificationService.fire(GlobalNotificationSetting.EVENT.PAGE_LIKE, page, req.user);
+      }
+      catch (err) {
+        logger.error('Like notification failed', err);
+      }
+    }
   });
   });
 
 
   /**
   /**