Add MondayCom option to add updates to an item. Make options alphabetical.

This commit is contained in:
Robarelli 2020-06-07 23:57:39 -06:00 committed by Rob Cunning
parent d2e738b5c7
commit 8e86443bdb
2 changed files with 231 additions and 167 deletions

View file

@ -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[];

View file

@ -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);