Explorar o código

Merge pull request #6029 from MialLewis/add_archive_card_to_api

Add archive card to api
Lauri Ojansivu hai 3 semanas
pai
achega
41c635afb5
Modificáronse 2 ficheiros con 169 adicións e 0 borrados
  1. 77 0
      models/cards.js
  2. 92 0
      public/api/wekan.yml

+ 77 - 0
models/cards.js

@@ -4440,6 +4440,83 @@ JsonRoutes.add('GET', '/api/boards/:boardId/cards_count', function(
       });
       });
     },
     },
   );
   );
+
+  /**
+  * @operation archive_card
+  * @summary Archive a card
+  *
+  * @description Archive a card
+  * @param {string} boardId the board ID of the card
+  * @param {string} listId the list ID of the card
+  * @param {string} cardId the ID of the card
+  * @return_type {_id: string, archived: boolean, archivedAt: Date}
+  */
+  JsonRoutes.add(
+    'POST',
+    '/api/boards/:boardId/lists/:listId/cards/:cardId/archive',
+    function(req, res) {
+      const paramBoardId = req.params.boardId;
+      const paramCardId = req.params.cardId;
+      const paramListId = req.params.listId;
+      Authentication.checkBoardAccess(req.userId, paramBoardId);
+      const card = ReactiveCache.getCard({
+        _id: paramCardId,
+        listId: paramListId,
+        boardId: paramBoardId,
+        archived: false,
+      });
+      if (!card) {
+        throw new Meteor.Error(404, 'Card not found');
+      }
+      card.archive();
+      JsonRoutes.sendResult(res, {
+        code: 200,
+        data: {
+          _id: paramCardId,
+          archived: true,
+          archivedAt: new Date(),
+        },
+      });
+    },
+  );
+
+  /**
+  * @operation unarchive_card
+  * @summary Unarchive card
+  *
+  * @description Unarchive card
+  * @param {string} boardId the board ID of the card
+  * @param {string} listId the list ID of the card
+  * @param {string} cardId the ID of the card
+  * @return_type {_id: string, archived: boolean}
+  */
+  JsonRoutes.add(
+    'POST',
+    '/api/boards/:boardId/lists/:listId/cards/:cardId/unarchive',
+    function(req, res) {
+      const paramBoardId = req.params.boardId;
+      const paramCardId = req.params.cardId;
+      const paramListId = req.params.listId;
+      Authentication.checkBoardAccess(req.userId, paramBoardId);
+      const card = ReactiveCache.getCard({
+        _id: paramCardId,
+        listId: paramListId,
+        boardId: paramBoardId,
+        archived: true,
+      });
+      if (!card) {
+        throw new Meteor.Error(404, 'Card not found');
+      }
+      card.restore();
+      JsonRoutes.sendResult(res, {
+        code: 200,
+        data: {
+          _id: paramCardId,
+          archived: false,
+        },
+      });
+    },
+  );
 }
 }
 
 
 // Position history tracking methods
 // Position history tracking methods

+ 92 - 0
public/api/wekan.yml

@@ -2594,6 +2594,53 @@ paths:
             properties:
             properties:
               _id:
               _id:
                 type: string
                 type: string
+  /api/boards/{board}/lists/{list}/cards/{card}/archive:
+    post:
+      operationId: archive_card
+      summary: Archive a card
+      description: |
+        Archive a card
+      tags:
+        - Cards
+      consumes:
+        - multipart/form-data
+        - application/json
+      parameters:
+        - name: board
+          in: path
+          description: |
+            the board ID of the card
+          type: string
+          required: true
+        - name: list
+          in: path
+          description: |
+            the list ID of the card
+          type: string
+          required: true
+        - name: card
+          in: path
+          description: |
+            the ID of the card
+          type: string
+          required: true
+      produces:
+        - application/json
+      security:
+          - UserSecurity: []
+      responses:
+        '200':
+          description: |-
+            200 response
+          schema:
+            type: object
+            properties:
+              _id:
+                type: string
+              archived:
+                type: boolean
+              archivedAt:
+                type: string
   /api/boards/{board}/lists/{list}/cards/{card}/customFields/{customField}:
   /api/boards/{board}/lists/{list}/cards/{card}/customFields/{customField}:
     post:
     post:
       operationId: edit_card_custom_field
       operationId: edit_card_custom_field
@@ -2658,6 +2705,51 @@ paths:
                       type: string
                       type: string
                     value:
                     value:
                       type: object
                       type: object
+  /api/boards/{board}/lists/{list}/cards/{card}/unarchive:
+    post:
+      operationId: unarchive_card
+      summary: Unarchive card
+      description: |
+        Unarchive card
+      tags:
+        - Cards
+      consumes:
+        - multipart/form-data
+        - application/json
+      parameters:
+        - name: board
+          in: path
+          description: |
+            the board ID of the card
+          type: string
+          required: true
+        - name: list
+          in: path
+          description: |
+            the list ID of the card
+          type: string
+          required: true
+        - name: card
+          in: path
+          description: |
+            the ID of the card
+          type: string
+          required: true
+      produces:
+        - application/json
+      security:
+          - UserSecurity: []
+      responses:
+        '200':
+          description: |-
+            200 response
+          schema:
+            type: object
+            properties:
+              _id:
+                type: string
+              archived:
+                type: boolean
   /api/boards/{board}/lists/{list}/cards_count:
   /api/boards/{board}/lists/{list}/cards_count:
     get:
     get:
       operationId: get_list_cards_count
       operationId: get_list_cards_count