Преглед изворни кода

add a route '/_api/comments.remove'

Yuki Takei пре 8 година
родитељ
комит
a96ee56436
2 измењених фајлова са 22 додато и 0 уклоњено
  1. 21 0
      lib/routes/comment.js
  2. 1 0
      lib/routes/index.js

+ 21 - 0
lib/routes/comment.js

@@ -72,5 +72,26 @@ module.exports = function(crowi, app) {
       });
   };
 
+  /**
+   * @api {post} /comments.remove Remove specified comment
+   * @apiName RemoveComment
+   * @apiGroup Comment
+   *
+   * @apiParam {String} comment_id Comment Id.
+   */
+  api.remove = function(req, res){
+    var commentId = req.body.comment_id;
+    if (!commentId) {
+      return res.json(ApiResponse.error(`'comment_id' is undefined`));
+    }
+
+    return Comment.remove({_id: commentId})
+      .then(function() {
+        return res.json(ApiResponse.success({}));
+      }).catch(function(err) {
+        return res.json(ApiResponse.error(err));
+      });
+  };
+
   return actions;
 };

+ 1 - 0
lib/routes/index.js

@@ -119,6 +119,7 @@ module.exports = function(crowi, app) {
   app.post('/_api/pages.unlink'       , loginRequired(crowi, app) , csrf, page.api.unlink); // (Avoid from API Token)
   app.get('/_api/comments.get'        , accessTokenParser , loginRequired(crowi, app, false) , comment.api.get);
   app.post('/_api/comments.add'       , form.comment, accessTokenParser , loginRequired(crowi, app) , csrf, comment.api.add);
+  app.post('/_api/comments.remove'    , accessTokenParser , loginRequired(crowi, app) , csrf, comment.api.remove);
   app.get( '/_api/bookmarks.get'      , accessTokenParser , loginRequired(crowi, app, false) , bookmark.api.get);
   app.post('/_api/bookmarks.add'      , accessTokenParser , loginRequired(crowi, app) , csrf, bookmark.api.add);
   app.post('/_api/bookmarks.remove'   , accessTokenParser , loginRequired(crowi, app) , csrf, bookmark.api.remove);