From 586473aaa7d9047267751c9c8734a35cd3c0ad91 Mon Sep 17 00:00:00 2001 From: Louis Orleans Date: Fri, 19 Feb 2021 11:21:13 -0800 Subject: [PATCH 1/7] =?UTF-8?q?=E2=9C=A8=20add=20custom=20field=20edit=20R?= =?UTF-8?q?EST=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 From db666eec65f7d8695f57ed0f8d7dade77f8b68d7 Mon Sep 17 00:00:00 2001 From: Louis Orleans Date: Sat, 20 Feb 2021 09:02:12 -0800 Subject: [PATCH 2/7] =?UTF-8?q?=F0=9F=90=9B=20fix=20updating=20fields?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- models/customFields.js | 53 ++++++++++++------------------------------ 1 file changed, 15 insertions(+), 38 deletions(-) diff --git a/models/customFields.js b/models/customFields.js index cee4d9c1a..59e89ac2f 100644 --- a/models/customFields.js +++ b/models/customFields.js @@ -385,74 +385,51 @@ if (Meteor.isServer) { JsonRoutes.add( 'PUT', '/api/boards/:boardId/custom-fields/:customFieldId', - function(req, res) { + (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 } }, + { _id: paramFieldId }, + { $set: { name: req.body.name } }, ); } if (req.body.hasOwnProperty('type')) { CustomFields.direct.update( - { - _id: paramFieldId, - boardId: paramBoardId, - }, - { $set: { title: req.body.type } }, + { _id: paramFieldId }, + { $set: { type: 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 } }, + { _id: paramFieldId }, + { $set: { settings: req.body.settings } }, ); } if (req.body.hasOwnProperty('showOnCard')) { CustomFields.direct.update( - { - _id: paramFieldId, - boardId: paramBoardId, - }, - { $set: { title: req.body.showOnCard } }, + { _id: paramFieldId }, + { $set: { showOnCard: req.body.showOnCard } }, ); } if (req.body.hasOwnProperty('automaticallyOnCard')) { CustomFields.direct.update( - { - _id: paramFieldId, - boardId: paramBoardId, - }, - { $set: { title: req.body.automaticallyOnCard } }, + { _id: paramFieldId }, + { $set: { automaticallyOnCard: req.body.automaticallyOnCard } }, ); } if (req.body.hasOwnProperty('alwaysOnCard')) { CustomFields.direct.update( - { - _id: paramFieldId, - boardId: paramBoardId, - }, - { $set: { title: req.body.alwaysOnCard } }, + { _id: paramFieldId }, + { $set: { alwaysOnCard: req.body.alwaysOnCard } }, ); } if (req.body.hasOwnProperty('showLabelOnMiniCard')) { CustomFields.direct.update( - { - _id: paramFieldId, - boardId: paramBoardId, - }, - { $set: { title: req.body.showLabelOnMiniCard } }, + { _id: paramFieldId }, + { $set: { showLabelOnMiniCard: req.body.showLabelOnMiniCard } }, ); } From a35cfe660e753d74d2a7a655569c0782293dd789 Mon Sep 17 00:00:00 2001 From: Louis Orleans Date: Sat, 20 Feb 2021 09:02:36 -0800 Subject: [PATCH 3/7] =?UTF-8?q?=F0=9F=8E=A8=20format=20with=20Prettier?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- models/customFields.js | 102 +++++++++++++++++++++-------------------- 1 file changed, 52 insertions(+), 50 deletions(-) diff --git a/models/customFields.js b/models/customFields.js index 59e89ac2f..e8414e5a5 100644 --- a/models/customFields.js +++ b/models/customFields.js @@ -121,7 +121,7 @@ CustomFields.attachSchema( }), ); -CustomFields.addToAllCards = cf => { +CustomFields.addToAllCards = (cf) => { Cards.update( { boardId: { $in: cf.boardIds }, @@ -281,25 +281,26 @@ if (Meteor.isServer) { * name: string, * type: string}] */ - JsonRoutes.add('GET', '/api/boards/:boardId/custom-fields', function( - req, - res, - ) { - Authentication.checkUserId(req.userId); - const paramBoardId = req.params.boardId; - JsonRoutes.sendResult(res, { - code: 200, - data: CustomFields.find({ boardIds: { $in: [paramBoardId] } }).map( - function(cf) { - return { - _id: cf._id, - name: cf.name, - type: cf.type, - }; - }, - ), - }); - }); + JsonRoutes.add( + 'GET', + '/api/boards/:boardId/custom-fields', + function (req, res) { + Authentication.checkUserId(req.userId); + const paramBoardId = req.params.boardId; + JsonRoutes.sendResult(res, { + code: 200, + data: CustomFields.find({ boardIds: { $in: [paramBoardId] } }).map( + function (cf) { + return { + _id: cf._id, + name: cf.name, + type: cf.type, + }; + }, + ), + }); + }, + ); /** * @operation get_custom_field @@ -312,7 +313,7 @@ if (Meteor.isServer) { JsonRoutes.add( 'GET', '/api/boards/:boardId/custom-fields/:customFieldId', - function(req, res) { + function (req, res) { Authentication.checkUserId(req.userId); const paramBoardId = req.params.boardId; const paramCustomFieldId = req.params.customFieldId; @@ -339,36 +340,37 @@ if (Meteor.isServer) { * @param {boolean} showLabelOnMiniCard should the label of the custom field be shown on minicards? * @return_type {_id: string} */ - JsonRoutes.add('POST', '/api/boards/:boardId/custom-fields', function( - req, - res, - ) { - Authentication.checkUserId(req.userId); - const paramBoardId = req.params.boardId; - const board = Boards.findOne({ _id: paramBoardId }); - const id = CustomFields.direct.insert({ - name: req.body.name, - type: req.body.type, - settings: req.body.settings, - showOnCard: req.body.showOnCard, - automaticallyOnCard: req.body.automaticallyOnCard, - showLabelOnMiniCard: req.body.showLabelOnMiniCard, - boardIds: [board._id], - }); + JsonRoutes.add( + 'POST', + '/api/boards/:boardId/custom-fields', + function (req, res) { + Authentication.checkUserId(req.userId); + const paramBoardId = req.params.boardId; + const board = Boards.findOne({ _id: paramBoardId }); + const id = CustomFields.direct.insert({ + name: req.body.name, + type: req.body.type, + settings: req.body.settings, + showOnCard: req.body.showOnCard, + automaticallyOnCard: req.body.automaticallyOnCard, + showLabelOnMiniCard: req.body.showLabelOnMiniCard, + boardIds: [board._id], + }); - const customField = CustomFields.findOne({ - _id: id, - boardIds: { $in: [paramBoardId] }, - }); - customFieldCreation(req.body.authorId, customField); - - JsonRoutes.sendResult(res, { - code: 200, - data: { + const customField = CustomFields.findOne({ _id: id, - }, - }); - }); + boardIds: { $in: [paramBoardId] }, + }); + customFieldCreation(req.body.authorId, customField); + + JsonRoutes.sendResult(res, { + code: 200, + data: { + _id: id, + }, + }); + }, + ); /** * @operation edit_custom_field @@ -453,7 +455,7 @@ if (Meteor.isServer) { JsonRoutes.add( 'DELETE', '/api/boards/:boardId/custom-fields/:customFieldId', - function(req, res) { + function (req, res) { Authentication.checkUserId(req.userId); const paramBoardId = req.params.boardId; const id = req.params.customFieldId; From 373dc5cadba3b24c0c83d8aedccf6379d1ba1c32 Mon Sep 17 00:00:00 2001 From: Louis Orleans Date: Sat, 20 Feb 2021 09:27:33 -0800 Subject: [PATCH 4/7] =?UTF-8?q?=E2=8F=AA=20Revert=20"=F0=9F=8E=A8=20format?= =?UTF-8?q?=20with=20Prettier"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This reverts commit a35cfe660e753d74d2a7a655569c0782293dd789. --- models/customFields.js | 102 ++++++++++++++++++++--------------------- 1 file changed, 50 insertions(+), 52 deletions(-) diff --git a/models/customFields.js b/models/customFields.js index e8414e5a5..59e89ac2f 100644 --- a/models/customFields.js +++ b/models/customFields.js @@ -121,7 +121,7 @@ CustomFields.attachSchema( }), ); -CustomFields.addToAllCards = (cf) => { +CustomFields.addToAllCards = cf => { Cards.update( { boardId: { $in: cf.boardIds }, @@ -281,26 +281,25 @@ if (Meteor.isServer) { * name: string, * type: string}] */ - JsonRoutes.add( - 'GET', - '/api/boards/:boardId/custom-fields', - function (req, res) { - Authentication.checkUserId(req.userId); - const paramBoardId = req.params.boardId; - JsonRoutes.sendResult(res, { - code: 200, - data: CustomFields.find({ boardIds: { $in: [paramBoardId] } }).map( - function (cf) { - return { - _id: cf._id, - name: cf.name, - type: cf.type, - }; - }, - ), - }); - }, - ); + JsonRoutes.add('GET', '/api/boards/:boardId/custom-fields', function( + req, + res, + ) { + Authentication.checkUserId(req.userId); + const paramBoardId = req.params.boardId; + JsonRoutes.sendResult(res, { + code: 200, + data: CustomFields.find({ boardIds: { $in: [paramBoardId] } }).map( + function(cf) { + return { + _id: cf._id, + name: cf.name, + type: cf.type, + }; + }, + ), + }); + }); /** * @operation get_custom_field @@ -313,7 +312,7 @@ if (Meteor.isServer) { JsonRoutes.add( 'GET', '/api/boards/:boardId/custom-fields/:customFieldId', - function (req, res) { + function(req, res) { Authentication.checkUserId(req.userId); const paramBoardId = req.params.boardId; const paramCustomFieldId = req.params.customFieldId; @@ -340,37 +339,36 @@ if (Meteor.isServer) { * @param {boolean} showLabelOnMiniCard should the label of the custom field be shown on minicards? * @return_type {_id: string} */ - JsonRoutes.add( - 'POST', - '/api/boards/:boardId/custom-fields', - function (req, res) { - Authentication.checkUserId(req.userId); - const paramBoardId = req.params.boardId; - const board = Boards.findOne({ _id: paramBoardId }); - const id = CustomFields.direct.insert({ - name: req.body.name, - type: req.body.type, - settings: req.body.settings, - showOnCard: req.body.showOnCard, - automaticallyOnCard: req.body.automaticallyOnCard, - showLabelOnMiniCard: req.body.showLabelOnMiniCard, - boardIds: [board._id], - }); + JsonRoutes.add('POST', '/api/boards/:boardId/custom-fields', function( + req, + res, + ) { + Authentication.checkUserId(req.userId); + const paramBoardId = req.params.boardId; + const board = Boards.findOne({ _id: paramBoardId }); + const id = CustomFields.direct.insert({ + name: req.body.name, + type: req.body.type, + settings: req.body.settings, + showOnCard: req.body.showOnCard, + automaticallyOnCard: req.body.automaticallyOnCard, + showLabelOnMiniCard: req.body.showLabelOnMiniCard, + boardIds: [board._id], + }); - const customField = CustomFields.findOne({ + const customField = CustomFields.findOne({ + _id: id, + boardIds: { $in: [paramBoardId] }, + }); + customFieldCreation(req.body.authorId, customField); + + JsonRoutes.sendResult(res, { + code: 200, + data: { _id: id, - boardIds: { $in: [paramBoardId] }, - }); - customFieldCreation(req.body.authorId, customField); - - JsonRoutes.sendResult(res, { - code: 200, - data: { - _id: id, - }, - }); - }, - ); + }, + }); + }); /** * @operation edit_custom_field @@ -455,7 +453,7 @@ if (Meteor.isServer) { JsonRoutes.add( 'DELETE', '/api/boards/:boardId/custom-fields/:customFieldId', - function (req, res) { + function(req, res) { Authentication.checkUserId(req.userId); const paramBoardId = req.params.boardId; const id = req.params.customFieldId; From 457977f9541606305eb89095855fc9292e7696ff Mon Sep 17 00:00:00 2001 From: Louis Orleans Date: Sat, 20 Feb 2021 12:46:29 -0800 Subject: [PATCH 5/7] =?UTF-8?q?=E2=9C=A8=20add=20and=20remove=20dropdown?= =?UTF-8?q?=20items?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- models/customFields.js | 65 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) diff --git a/models/customFields.js b/models/customFields.js index 59e89ac2f..276177fe9 100644 --- a/models/customFields.js +++ b/models/customFields.js @@ -440,6 +440,71 @@ if (Meteor.isServer) { }, ); + /** + * @operation add_custom_field_dropdown_items + * @summary Update a Custom Field's dropdown items + * + * @param {string[]} items names of the custom field + * @return_type {_id: string} + */ + JsonRoutes.add( + 'POST', + '/api/boards/:boardId/custom-fields/:customFieldId/dropdown-items', + (req, res) => { + Authentication.checkUserId(req.userId); + + if (req.body.hasOwnProperty('items')) { + CustomFields.direct.update( + { _id: req.params.customFieldId }, + { + $push: { + 'settings.dropdownItems': { + $each: req.body.items.map(name => ({ + _id: Random.id(6), + name, + })), + }, + }, + }, + ); + } + + JsonRoutes.sendResult(res, { + code: 200, + data: { _id: req.params.customFieldId }, + }); + }, + ); + + /** + * @operation delete_custom_field_dropdown_item + * @summary Update a Custom Field's dropdown items + * + * @param {string} itemId ID of the dropdown item + * @return_type {_id: string} + */ + JsonRoutes.add( + 'DELETE', + '/api/boards/:boardId/custom-fields/:customFieldId/dropdown-items/:dropdownItemId', + (req, res) => { + Authentication.checkUserId(req.userId); + + CustomFields.direct.update( + { _id: req.params.customFieldId }, + { + $pull: { + 'settings.dropdownItems': { _id: req.params.dropdownItemId }, + }, + }, + ); + + JsonRoutes.sendResult(res, { + code: 200, + data: { _id: req.params.customFieldId }, + }); + }, + ); + /** * @operation delete_custom_field * @summary Delete a Custom Fields attached to a board From 24035329b8249c83ac323ddfdabeceb5da0768a1 Mon Sep 17 00:00:00 2001 From: Louis Orleans Date: Sat, 20 Feb 2021 13:50:24 -0800 Subject: [PATCH 6/7] =?UTF-8?q?=E2=9C=A8=20edit=20custom=20field=20dropdow?= =?UTF-8?q?n=20item?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- models/customFields.js | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/models/customFields.js b/models/customFields.js index 276177fe9..cb69a761b 100644 --- a/models/customFields.js +++ b/models/customFields.js @@ -476,6 +476,43 @@ if (Meteor.isServer) { }, ); + /** + * @operation edit_custom_field_dropdown_item + * @summary Update a Custom Field's dropdown item + * + * @param {string} name names of the custom field + * @return_type {_id: string} + */ + JsonRoutes.add( + 'PUT', + '/api/boards/:boardId/custom-fields/:customFieldId/dropdown-items/:dropdownItemId', + (req, res) => { + Authentication.checkUserId(req.userId); + + if (req.body.hasOwnProperty('name')) { + CustomFields.direct.update( + { + _id: req.params.customFieldId, + 'settings.dropdownItems._id': req.params.dropdownItemId, + }, + { + $set: { + 'settings.dropdownItems.$': { + _id: req.params.dropdownItemId, + name: req.body.name, + }, + }, + }, + ); + } + + JsonRoutes.sendResult(res, { + code: 200, + data: { _id: req.params.customFieldId }, + }); + }, + ); + /** * @operation delete_custom_field_dropdown_item * @summary Update a Custom Field's dropdown items From 9cbef4ba4b2e0a12bee5884abf7f771132d04ecd Mon Sep 17 00:00:00 2001 From: Louis Orleans Date: Sat, 20 Feb 2021 14:11:17 -0800 Subject: [PATCH 7/7] =?UTF-8?q?=F0=9F=94=92=20fix=20warning=20from=20deepc?= =?UTF-8?q?ode?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- models/customFields.js | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/models/customFields.js b/models/customFields.js index cb69a761b..3996a3843 100644 --- a/models/customFields.js +++ b/models/customFields.js @@ -453,16 +453,18 @@ if (Meteor.isServer) { (req, res) => { Authentication.checkUserId(req.userId); - if (req.body.hasOwnProperty('items')) { + if (req.body.hasOwnProperty('items') && Array.isArray(req.body.items)) { CustomFields.direct.update( { _id: req.params.customFieldId }, { $push: { 'settings.dropdownItems': { - $each: req.body.items.map(name => ({ - _id: Random.id(6), - name, - })), + $each: req.body.items + .filter(name => typeof name === 'string') + .map(name => ({ + _id: Random.id(6), + name, + })), }, }, },