Browse Source

REST API: List attachments of a board.

For using this, Python code example:
https://github.com/wekan/wekan/wiki/New-card-with-Python3-and-REST-API

Thanks to xet7 !

Related #1482
Lauri Ojansivu 4 years ago
parent
commit
bf94161f30
1 changed files with 35 additions and 0 deletions
  1. 35 0
      models/boards.js

+ 35 - 0
models/boards.js

@@ -1753,6 +1753,41 @@ if (Meteor.isServer) {
       });
     }
   });
+
+  //ATTACHMENTS REST API
+  /**
+   * @operation get_board_attachments
+   * @summary Get the list of attachments of a board
+   *
+   * @param {string} boardId the board ID
+   * @return_type [{attachmentId: string,
+   *                attachmentName: string,
+   *                attachmentType: string,
+   *                cardId: string,
+   *                listId: string,
+   *                swimlaneId: string}]
+   */
+  JsonRoutes.add('GET', '/api/boards/:boardId/attachments', function(req, res) {
+    const paramBoardId = req.params.boardId;
+    Authentication.checkBoardAccess(req.userId, paramBoardId);
+    JsonRoutes.sendResult(res, {
+      code: 200,
+      data: Attachments.files
+        .find({ boardId: paramBoardId }, { fields: { boardId: 0 } })
+        .map(function(doc) {
+          return {
+            attachmentId: doc._id,
+            // this preserves the name so that notifications can be meaningful after
+            // this file is removed
+            attachmentName: doc.original.name,
+            attachmentType: doc.original.type,
+            cardId: doc.cardId,
+            listId: doc.listId,
+            swimlaneId: doc.swimlaneId,
+          };
+        }),
+    });
+  });
 }
 
 export default Boards;