From 586473aaa7d9047267751c9c8734a35cd3c0ad91 Mon Sep 17 00:00:00 2001 From: Louis Orleans Date: Fri, 19 Feb 2021 11:21:13 -0800 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20add=20custom=20field=20edit=20REST?= =?UTF-8?q?=20API?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- models/customFields.js | 93 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 93 insertions(+) diff --git a/models/customFields.js b/models/customFields.js index 280f87749..cee4d9c1a 100644 --- a/models/customFields.js +++ b/models/customFields.js @@ -370,6 +370,99 @@ if (Meteor.isServer) { }); }); + /** + * @operation edit_custom_field + * @summary Update a Custom Field + * + * @param {string} name the name of the custom field + * @param {string} type the type of the custom field + * @param {string} settings the settings object of the custom field + * @param {boolean} showOnCard should we show the custom field on cards? + * @param {boolean} automaticallyOnCard should the custom fields automatically be added on cards? + * @param {boolean} showLabelOnMiniCard should the label of the custom field be shown on minicards? + * @return_type {_id: string} + */ + JsonRoutes.add( + 'PUT', + '/api/boards/:boardId/custom-fields/:customFieldId', + function(req, res) { + Authentication.checkUserId(req.userId); + + const paramFieldId = req.params.customFieldId; + const paramBoardId = req.params.boardId; + + if (req.body.hasOwnProperty('name')) { + CustomFields.direct.update( + { + _id: paramFieldId, + boardId: paramBoardId, + }, + { $set: { title: req.body.name } }, + ); + } + if (req.body.hasOwnProperty('type')) { + CustomFields.direct.update( + { + _id: paramFieldId, + boardId: paramBoardId, + }, + { $set: { title: req.body.type } }, + ); + } + if (req.body.hasOwnProperty('settings')) { + CustomFields.direct.update( + { + _id: paramFieldId, + boardId: paramBoardId, + }, + // TODO: should I just wholesale set the settings obj? + { $set: { title: req.body.settings } }, + ); + } + if (req.body.hasOwnProperty('showOnCard')) { + CustomFields.direct.update( + { + _id: paramFieldId, + boardId: paramBoardId, + }, + { $set: { title: req.body.showOnCard } }, + ); + } + if (req.body.hasOwnProperty('automaticallyOnCard')) { + CustomFields.direct.update( + { + _id: paramFieldId, + boardId: paramBoardId, + }, + { $set: { title: req.body.automaticallyOnCard } }, + ); + } + if (req.body.hasOwnProperty('alwaysOnCard')) { + CustomFields.direct.update( + { + _id: paramFieldId, + boardId: paramBoardId, + }, + { $set: { title: req.body.alwaysOnCard } }, + ); + } + if (req.body.hasOwnProperty('showLabelOnMiniCard')) { + CustomFields.direct.update( + { + _id: paramFieldId, + boardId: paramBoardId, + }, + { $set: { title: req.body.showLabelOnMiniCard } }, + ); + } + + JsonRoutes.sendResult(res, { + code: 200, + data: { _id: paramFieldId }, + }); + }, + ); + /** * @operation delete_custom_field * @summary Delete a Custom Fields attached to a board