From e9e3e146952573109a59804ed265e5522accc544 Mon Sep 17 00:00:00 2001 From: DimDz <70445835+DimDz@users.noreply.github.com> Date: Tue, 2 May 2023 15:08:14 +0300 Subject: [PATCH 1/2] Update checklists.js https://github.com/wekan/wekan/issues/4562 --- models/checklists.js | 45 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/models/checklists.js b/models/checklists.js index 302becdb9..cd8d3fb80 100644 --- a/models/checklists.js +++ b/models/checklists.js @@ -383,6 +383,51 @@ if (Meteor.isServer) { }, ); + /** + * @operation new_checklist_item + * @summary add a new item to a checklist + * + * @param {string} boardId the board ID + * @param {string} cardId the card ID + * @param {string} checklistId the ID of the checklist + * @param {string} title the title of the new item + * @return_type {_id: string} + */ + + JsonRoutes.add( + 'POST', + '/api/boards/:boardId/cards/:cardId/checklists/:checklistId/items', + function(req, res) { + const paramBoardId = req.params.boardId; + const paramChecklistId = req.params.checklistId; + const paramCardId = req.params.cardId; + Authentication.checkBoardAccess(req.userId, paramBoardId); + const checklist = Checklists.findOne({ + _id: paramChecklistId, + cardId: paramCardId, + }); + if (checklist) { + const id = ChecklistItems.insert({ + cardId: paramCardId, + checklistId: paramChecklistId, + title: req.body.title, + isFinished: false, + sort: 0, + }); + JsonRoutes.sendResult(res, { + code: 200, + data: { + _id: id, + }, + }); + } else { + JsonRoutes.sendResult(res, { + code: 404, + }); + } + }, + ); + /** * @operation delete_checklist * @summary Delete a checklist From ad26e57e78c13d68cddfb32061dfd219663b46f6 Mon Sep 17 00:00:00 2001 From: DimDz <70445835+DimDz@users.noreply.github.com> Date: Tue, 2 May 2023 16:39:49 +0300 Subject: [PATCH 2/2] @operation edit_card_custom_field --- models/cards.js | 60 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) diff --git a/models/cards.js b/models/cards.js index ceb410071..1b08d34f4 100644 --- a/models/cards.js +++ b/models/cards.js @@ -3924,6 +3924,66 @@ JsonRoutes.add('GET', '/api/boards/:boardId/cards_count', function( }); }, ); + + /** + * @operation edit_card_custom_field + * @summary Edit Custom Field in a Card + * + * @description Edit a custom field value in 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 + * @param {string} customFieldId the ID of the custom field + * @param {string} value the new custom field value + * @return_type {_id: string, customFields: object} + */ + JsonRoutes.add( + 'POST', + '/api/boards/:boardId/lists/:listId/cards/:cardId/customFields/:customFieldId', + function(req, res) { + const paramBoardId = req.params.boardId; + const paramCardId = req.params.cardId; + const paramListId = req.params.listId; + const paramCustomFieldId = req.params.customFieldId; + const paramCustomFieldValue = req.body.value; + Authentication.checkBoardAccess(req.userId, paramBoardId); + const card = Cards.findOne({ + _id: paramCardId, + listId: paramListId, + boardId: paramBoardId, + archived: false, + }); + if (!card) { + throw new Meteor.Error(404, 'Card not found'); + } + const customFields = card.customFields || []; + const updatedCustomFields = customFields.map(cf => { + if (cf._id === paramCustomFieldId) { + return { + _id: cf._id, + value: paramCustomFieldValue, + }; + } + return cf; + }); + Cards.direct.update( + { + _id: paramCardId, + listId: paramListId, + boardId: paramBoardId, + archived: false, + }, + { $set: { customFields: updatedCustomFields } }, + ); + JsonRoutes.sendResult(res, { + code: 200, + data: { + _id: paramCardId, + customFields: updatedCustomFields, + }, + }); + }, + ); } export default Cards;