From d2e738b5c7a9c7e8d09fda24047da236a071be38 Mon Sep 17 00:00:00 2001 From: Robarelli Date: Sun, 7 Jun 2020 23:34:10 -0600 Subject: [PATCH 1/2] Add MondayCom options for changing column values --- .../nodes/MondayCom/BoardItemDescription.ts | 157 ++++++++++++++++++ .../nodes/MondayCom/MondayCom.node.ts | 58 +++++++ 2 files changed, 215 insertions(+) diff --git a/packages/nodes-base/nodes/MondayCom/BoardItemDescription.ts b/packages/nodes-base/nodes/MondayCom/BoardItemDescription.ts index c6725279ed..c3f81484f9 100644 --- a/packages/nodes-base/nodes/MondayCom/BoardItemDescription.ts +++ b/packages/nodes-base/nodes/MondayCom/BoardItemDescription.ts @@ -15,6 +15,16 @@ export const boardItemOperations = [ }, }, options: [ + { + name: 'Change Column Value', + value: 'changeColumnValue', + description: 'Change a column value for a board item', + }, + { + name: 'Change Multiple Column Values', + value: 'changeMultipleColumnValues', + description: 'Change multiple column values for a board item', + }, { name: 'Create', value: 'create', @@ -377,4 +387,151 @@ export const boardItemFields = [ default: 50, description: 'How many results to return.', }, +/* -------------------------------------------------------------------------- */ +/* boardItem:changeColumnValue */ +/* -------------------------------------------------------------------------- */ + { + displayName: 'Board ID', + name: 'boardId', + type: 'options', + typeOptions: { + loadOptionsMethod: 'getBoards', + }, + default: '', + required: true, + displayOptions: { + show: { + resource: [ + 'boardItem', + ], + operation: [ + 'changeColumnValue', + ], + }, + }, + description: 'The unique identifier of the board.', + }, + { + displayName: 'Item ID', + name: 'itemId', + type: 'string', + default: '', + required: true, + displayOptions: { + show: { + resource: [ + 'boardItem', + ], + operation: [ + 'changeColumnValue', + ], + }, + }, + description: `Item's ID` + }, + { + displayName: 'Column ID', + name: 'columnId', + type: 'options', + typeOptions: { + loadOptionsMethod: 'getColumns', + loadOptionsDependsOn: [ + 'boardId' + ], + }, + default: '', + required: true, + displayOptions: { + show: { + resource: [ + 'boardItem', + ], + operation: [ + 'changeColumnValue', + ], + }, + }, + description: `The column's unique identifier.`, + }, + { + displayName: 'Value', + name: 'value', + type: 'json', + required: true, + default: '', + displayOptions: { + show: { + resource: [ + 'boardItem', + ], + operation: [ + 'changeColumnValue', + ], + }, + }, + description: 'The column value in JSON format.', + }, +/* -------------------------------------------------------------------------- */ +/* boardItem:changeMultipleColumnValues */ +/* -------------------------------------------------------------------------- */ + { + displayName: 'Board ID', + name: 'boardId', + type: 'options', + typeOptions: { + loadOptionsMethod: 'getBoards', + }, + default: '', + required: true, + displayOptions: { + show: { + resource: [ + 'boardItem', + ], + operation: [ + 'changeMultipleColumnValues', + ], + }, + }, + description: 'The unique identifier of the board.', + }, + { + displayName: 'Item ID', + name: 'itemId', + type: 'string', + default: '', + required: true, + displayOptions: { + show: { + resource: [ + 'boardItem', + ], + operation: [ + 'changeMultipleColumnValues', + ], + }, + }, + description: `Item's ID` + }, + { + displayName: 'Column Values', + name: 'columnValues', + type: 'json', + required: true, + default: '', + displayOptions: { + show: { + resource: [ + 'boardItem', + ], + operation: [ + 'changeMultipleColumnValues', + ], + }, + }, + description: 'The column fields and values in JSON format.', + typeOptions: { + alwaysOpenEditWindow: true, + }, + }, ] as INodeProperties[]; diff --git a/packages/nodes-base/nodes/MondayCom/MondayCom.node.ts b/packages/nodes-base/nodes/MondayCom/MondayCom.node.ts index f8e538e5cb..26ccdfa06e 100644 --- a/packages/nodes-base/nodes/MondayCom/MondayCom.node.ts +++ b/packages/nodes-base/nodes/MondayCom/MondayCom.node.ts @@ -487,6 +487,64 @@ export class MondayCom implements INodeType { responseData = await mondayComApiRequest.call(this, body); responseData = responseData.data.create_item; } + if (operation === 'changeColumnValue') { + const boardId = parseInt(this.getNodeParameter('boardId', i) as string, 10); + const itemId = parseInt((this.getNodeParameter('itemId', i) as string), 10); + const columnId = this.getNodeParameter('columnId', i) as string; + const value = this.getNodeParameter('value', i) as string; + + const body: IGraphqlBody = { + query: + `mutation ($boardId: Int!, $itemId: Int!, $columnId: String!, $value: JSON!) { + change_column_value (board_id: $boardId, item_id: $itemId, column_id: $columnId, value: $value) { + id + } + }`, + variables: { + boardId, + itemId, + columnId, + }, + }; + + try { + JSON.parse(value); + } catch (e) { + throw new Error('Custom Values must be a valid JSON'); + } + body.variables.value = JSON.stringify(JSON.parse(value)); + + responseData = await mondayComApiRequest.call(this, body); + responseData = responseData.data.change_column_value; + } + if (operation === 'changeMultipleColumnValues') { + const boardId = parseInt(this.getNodeParameter('boardId', i) as string, 10); + const itemId = parseInt((this.getNodeParameter('itemId', i) as string), 10); + const columnValues = this.getNodeParameter('columnValues', i) as string; + + const body: IGraphqlBody = { + query: + `mutation ($boardId: Int!, $itemId: Int!, $columnValues: JSON!) { + change_multiple_column_values (board_id: $boardId, item_id: $itemId, column_values: $columnValues) { + id + } + }`, + variables: { + boardId, + itemId, + }, + }; + + try { + JSON.parse(columnValues); + } catch (e) { + throw new Error('Custom Values must be a valid JSON'); + } + body.variables.columnValues = JSON.stringify(JSON.parse(columnValues)); + + responseData = await mondayComApiRequest.call(this, body); + responseData = responseData.data.change_multiple_column_values; + } if (operation === 'delete') { const itemId = parseInt((this.getNodeParameter('itemId', i) as string), 10); From 8e86443bdb88f0a77bb59f422844c25c2f425232 Mon Sep 17 00:00:00 2001 From: Robarelli Date: Sun, 7 Jun 2020 23:57:39 -0600 Subject: [PATCH 2/2] Add MondayCom option to add updates to an item. Make options alphabetical. --- .../nodes/MondayCom/BoardItemDescription.ts | 338 ++++++++++-------- .../nodes/MondayCom/MondayCom.node.ts | 60 ++-- 2 files changed, 231 insertions(+), 167 deletions(-) diff --git a/packages/nodes-base/nodes/MondayCom/BoardItemDescription.ts b/packages/nodes-base/nodes/MondayCom/BoardItemDescription.ts index c3f81484f9..4f8cfccecc 100644 --- a/packages/nodes-base/nodes/MondayCom/BoardItemDescription.ts +++ b/packages/nodes-base/nodes/MondayCom/BoardItemDescription.ts @@ -15,6 +15,11 @@ export const boardItemOperations = [ }, }, options: [ + { + name: 'Add Update', + value: 'addUpdate', + description: `Add an update to an item.`, + }, { name: 'Change Column Value', value: 'changeColumnValue', @@ -58,6 +63,192 @@ export const boardItemOperations = [ export const boardItemFields = [ +/* -------------------------------------------------------------------------- */ +/* boardItem:addUpdate */ +/* -------------------------------------------------------------------------- */ + { + displayName: 'Item ID', + name: 'itemId', + type: 'string', + default: '', + required: true, + displayOptions: { + show: { + resource: [ + 'boardItem', + ], + operation: [ + 'addUpdate', + ], + }, + }, + description: `Item's ID` + }, + { + displayName: 'Body', + name: 'value', + type: 'string', + required: true, + default: '', + displayOptions: { + show: { + resource: [ + 'boardItem', + ], + operation: [ + 'addUpdate', + ], + }, + }, + description: 'The update text', + }, +/* -------------------------------------------------------------------------- */ +/* boardItem:changeColumnValue */ +/* -------------------------------------------------------------------------- */ + { + displayName: 'Board ID', + name: 'boardId', + type: 'options', + typeOptions: { + loadOptionsMethod: 'getBoards', + }, + default: '', + required: true, + displayOptions: { + show: { + resource: [ + 'boardItem', + ], + operation: [ + 'changeColumnValue', + ], + }, + }, + description: 'The unique identifier of the board.', + }, + { + displayName: 'Item ID', + name: 'itemId', + type: 'string', + default: '', + required: true, + displayOptions: { + show: { + resource: [ + 'boardItem', + ], + operation: [ + 'changeColumnValue', + ], + }, + }, + description: `Item's ID` + }, + { + displayName: 'Column ID', + name: 'columnId', + type: 'options', + typeOptions: { + loadOptionsMethod: 'getColumns', + loadOptionsDependsOn: [ + 'boardId' + ], + }, + default: '', + required: true, + displayOptions: { + show: { + resource: [ + 'boardItem', + ], + operation: [ + 'changeColumnValue', + ], + }, + }, + description: `The column's unique identifier.`, + }, + { + displayName: 'Value', + name: 'value', + type: 'json', + required: true, + default: '', + displayOptions: { + show: { + resource: [ + 'boardItem', + ], + operation: [ + 'changeColumnValue', + ], + }, + }, + description: 'The column value in JSON format.', + }, +/* -------------------------------------------------------------------------- */ +/* boardItem:changeMultipleColumnValues */ +/* -------------------------------------------------------------------------- */ + { + displayName: 'Board ID', + name: 'boardId', + type: 'options', + typeOptions: { + loadOptionsMethod: 'getBoards', + }, + default: '', + required: true, + displayOptions: { + show: { + resource: [ + 'boardItem', + ], + operation: [ + 'changeMultipleColumnValues', + ], + }, + }, + description: 'The unique identifier of the board.', + }, + { + displayName: 'Item ID', + name: 'itemId', + type: 'string', + default: '', + required: true, + displayOptions: { + show: { + resource: [ + 'boardItem', + ], + operation: [ + 'changeMultipleColumnValues', + ], + }, + }, + description: `Item's ID` + }, + { + displayName: 'Column Values', + name: 'columnValues', + type: 'json', + required: true, + default: '', + displayOptions: { + show: { + resource: [ + 'boardItem', + ], + operation: [ + 'changeMultipleColumnValues', + ], + }, + }, + description: 'The column fields and values in JSON format.', + typeOptions: { + alwaysOpenEditWindow: true, + }, + }, /* -------------------------------------------------------------------------- */ /* boardItem:create */ /* -------------------------------------------------------------------------- */ @@ -387,151 +578,4 @@ export const boardItemFields = [ default: 50, description: 'How many results to return.', }, -/* -------------------------------------------------------------------------- */ -/* boardItem:changeColumnValue */ -/* -------------------------------------------------------------------------- */ - { - displayName: 'Board ID', - name: 'boardId', - type: 'options', - typeOptions: { - loadOptionsMethod: 'getBoards', - }, - default: '', - required: true, - displayOptions: { - show: { - resource: [ - 'boardItem', - ], - operation: [ - 'changeColumnValue', - ], - }, - }, - description: 'The unique identifier of the board.', - }, - { - displayName: 'Item ID', - name: 'itemId', - type: 'string', - default: '', - required: true, - displayOptions: { - show: { - resource: [ - 'boardItem', - ], - operation: [ - 'changeColumnValue', - ], - }, - }, - description: `Item's ID` - }, - { - displayName: 'Column ID', - name: 'columnId', - type: 'options', - typeOptions: { - loadOptionsMethod: 'getColumns', - loadOptionsDependsOn: [ - 'boardId' - ], - }, - default: '', - required: true, - displayOptions: { - show: { - resource: [ - 'boardItem', - ], - operation: [ - 'changeColumnValue', - ], - }, - }, - description: `The column's unique identifier.`, - }, - { - displayName: 'Value', - name: 'value', - type: 'json', - required: true, - default: '', - displayOptions: { - show: { - resource: [ - 'boardItem', - ], - operation: [ - 'changeColumnValue', - ], - }, - }, - description: 'The column value in JSON format.', - }, -/* -------------------------------------------------------------------------- */ -/* boardItem:changeMultipleColumnValues */ -/* -------------------------------------------------------------------------- */ - { - displayName: 'Board ID', - name: 'boardId', - type: 'options', - typeOptions: { - loadOptionsMethod: 'getBoards', - }, - default: '', - required: true, - displayOptions: { - show: { - resource: [ - 'boardItem', - ], - operation: [ - 'changeMultipleColumnValues', - ], - }, - }, - description: 'The unique identifier of the board.', - }, - { - displayName: 'Item ID', - name: 'itemId', - type: 'string', - default: '', - required: true, - displayOptions: { - show: { - resource: [ - 'boardItem', - ], - operation: [ - 'changeMultipleColumnValues', - ], - }, - }, - description: `Item's ID` - }, - { - displayName: 'Column Values', - name: 'columnValues', - type: 'json', - required: true, - default: '', - displayOptions: { - show: { - resource: [ - 'boardItem', - ], - operation: [ - 'changeMultipleColumnValues', - ], - }, - }, - description: 'The column fields and values in JSON format.', - typeOptions: { - alwaysOpenEditWindow: true, - }, - }, ] as INodeProperties[]; diff --git a/packages/nodes-base/nodes/MondayCom/MondayCom.node.ts b/packages/nodes-base/nodes/MondayCom/MondayCom.node.ts index 26ccdfa06e..5dc7457081 100644 --- a/packages/nodes-base/nodes/MondayCom/MondayCom.node.ts +++ b/packages/nodes-base/nodes/MondayCom/MondayCom.node.ts @@ -455,37 +455,25 @@ export class MondayCom implements INodeType { } } if (resource === 'boardItem') { - if (operation === 'create') { - const boardId = parseInt(this.getNodeParameter('boardId', i) as string, 10); - const groupId = this.getNodeParameter('groupId', i) as string; - const itemName = this.getNodeParameter('name', i) as string; - const additionalFields = this.getNodeParameter('additionalFields', i) as IDataObject; + if (operation === 'addUpdate') { + const itemId = parseInt((this.getNodeParameter('itemId', i) as string), 10); + const value = this.getNodeParameter('value', i) as string; const body: IGraphqlBody = { query: - `mutation ($boardId: Int!, $groupId: String!, $itemName: String!, $columnValues: JSON) { - create_item (board_id: $boardId, group_id: $groupId, item_name: $itemName, column_values: $columnValues) { + `mutation ($itemId: Int!, $value: String!) { + create_update (item_id: $itemId, body: $value) { id } }`, variables: { - boardId, - groupId, - itemName, + itemId, + value, }, }; - if (additionalFields.columnValues) { - try { - JSON.parse(additionalFields.columnValues as string); - } catch (e) { - throw new Error('Custom Values must be a valid JSON'); - } - body.variables.columnValues = JSON.stringify(JSON.parse(additionalFields.columnValues as string)); - } - responseData = await mondayComApiRequest.call(this, body); - responseData = responseData.data.create_item; + responseData = responseData.data.create_update; } if (operation === 'changeColumnValue') { const boardId = parseInt(this.getNodeParameter('boardId', i) as string, 10); @@ -545,6 +533,38 @@ export class MondayCom implements INodeType { responseData = await mondayComApiRequest.call(this, body); responseData = responseData.data.change_multiple_column_values; } + if (operation === 'create') { + const boardId = parseInt(this.getNodeParameter('boardId', i) as string, 10); + const groupId = this.getNodeParameter('groupId', i) as string; + const itemName = this.getNodeParameter('name', i) as string; + const additionalFields = this.getNodeParameter('additionalFields', i) as IDataObject; + + const body: IGraphqlBody = { + query: + `mutation ($boardId: Int!, $groupId: String!, $itemName: String!, $columnValues: JSON) { + create_item (board_id: $boardId, group_id: $groupId, item_name: $itemName, column_values: $columnValues) { + id + } + }`, + variables: { + boardId, + groupId, + itemName, + }, + }; + + if (additionalFields.columnValues) { + try { + JSON.parse(additionalFields.columnValues as string); + } catch (e) { + throw new Error('Custom Values must be a valid JSON'); + } + body.variables.columnValues = JSON.stringify(JSON.parse(additionalFields.columnValues as string)); + } + + responseData = await mondayComApiRequest.call(this, body); + responseData = responseData.data.create_item; + } if (operation === 'delete') { const itemId = parseInt((this.getNodeParameter('itemId', i) as string), 10);