Add card comment operation

This commit is contained in:
ricardo 2020-08-24 20:55:57 -04:00
parent f5c8fbe953
commit 4c075db26c
10 changed files with 463 additions and 147 deletions

View file

@ -367,7 +367,7 @@ export class Airtable implements INodeType {
const operation = this.getNodeParameter('operation', 0) as string; const operation = this.getNodeParameter('operation', 0) as string;
const application = this.getNodeParameter('application', 0) as string; const application = this.getNodeParameter('application', 0) as string;
const table = this.getNodeParameter('table', 0) as string; const table = encodeURI(this.getNodeParameter('table', 0) as string);
let returnAll = false; let returnAll = false;
let endpoint = ''; let endpoint = '';

View file

@ -1,4 +1,6 @@
import { INodeProperties } from "n8n-workflow"; import {
INodeProperties,
} from "n8n-workflow";
export const attachmentOperations = [ export const attachmentOperations = [
// ---------------------------------- // ----------------------------------

View file

@ -1,4 +1,6 @@
import { INodeProperties } from "n8n-workflow"; import {
INodeProperties,
} from "n8n-workflow";
export const boardOperations = [ export const boardOperations = [
// ---------------------------------- // ----------------------------------

View file

@ -0,0 +1,177 @@
import {
INodeProperties,
} from "n8n-workflow";
export const cardCommentOperations = [
{
displayName: 'Operation',
name: 'operation',
type: 'options',
displayOptions: {
show: {
resource: [
'cardComment',
],
},
},
options: [
{
name: 'Add',
value: 'add',
description: 'Add a comment to a card',
},
{
name: 'Revove',
value: 'remove',
description: 'Remove a comment from a card',
},
{
name: 'Update',
value: 'update',
description: 'Update a comment in a card',
},
],
default: 'add',
description: 'The operation to perform.',
},
] as INodeProperties[];
export const cardCommentFields = [
// ----------------------------------
// cardComment:add
// ----------------------------------
{
displayName: 'Card ID',
name: 'cardId',
type: 'string',
default: '',
required: true,
displayOptions: {
show: {
operation: [
'add',
],
resource: [
'cardComment',
],
},
},
description: 'The id of the card',
},
{
displayName: 'Text',
name: 'text',
type: 'string',
default: '',
required: true,
displayOptions: {
show: {
operation: [
'add',
],
resource: [
'cardComment',
],
},
},
description: 'Text of the comment',
},
// ----------------------------------
// cardComment:remove
// ----------------------------------
{
displayName: 'Card ID',
name: 'cardId',
type: 'string',
default: '',
required: true,
displayOptions: {
show: {
operation: [
'remove',
],
resource: [
'cardComment',
],
},
},
description: 'The ID of the card.',
},
{
displayName: 'Comment ID',
name: 'commentId',
type: 'string',
default: '',
required: true,
displayOptions: {
show: {
operation: [
'remove',
],
resource: [
'cardComment',
],
},
},
description: 'The ID of the comment to delete.',
},
// ----------------------------------
// cardComment:update
// ----------------------------------
{
displayName: 'Card ID',
name: 'cardId',
type: 'string',
default: '',
required: true,
displayOptions: {
show: {
operation: [
'update',
],
resource: [
'cardComment',
],
},
},
description: 'The ID of the card to update.',
},
{
displayName: 'Comment ID',
name: 'commentId',
type: 'string',
default: '',
required: true,
displayOptions: {
show: {
operation: [
'update',
],
resource: [
'cardComment',
],
},
},
description: 'The ID of the comment to delete.',
},
{
displayName: 'Text',
name: 'text',
type: 'string',
default: '',
required: true,
displayOptions: {
show: {
operation: [
'update',
],
resource: [
'cardComment',
],
},
},
description: 'Text of the comment',
},
] as INodeProperties[];

View file

@ -1,4 +1,6 @@
import { INodeProperties } from "n8n-workflow"; import {
INodeProperties,
} from "n8n-workflow";
export const cardOperations = [ export const cardOperations = [
// ---------------------------------- // ----------------------------------

View file

@ -1,4 +1,6 @@
import { INodeProperties } from "n8n-workflow"; import {
INodeProperties,
} from 'n8n-workflow';
export const checklistOperations = [ export const checklistOperations = [
// ---------------------------------- // ----------------------------------

View file

@ -4,9 +4,13 @@ import {
ILoadOptionsFunctions, ILoadOptionsFunctions,
} from 'n8n-core'; } from 'n8n-core';
import { OptionsWithUri } from 'request'; import {
import { IDataObject } from 'n8n-workflow'; OptionsWithUri,
} from 'request';
import {
IDataObject,
} from 'n8n-workflow';
/** /**
* Make an API request to Trello * Make an API request to Trello

View file

@ -1,4 +1,6 @@
import { INodeProperties } from "n8n-workflow"; import {
INodeProperties,
} from 'n8n-workflow';
export const labelOperations = [ export const labelOperations = [
// ---------------------------------- // ----------------------------------

View file

@ -1,42 +1,46 @@
import { INodeProperties } from "n8n-workflow"; import {
INodeProperties,
} from 'n8n-workflow';
export const listOperations = [ export const listOperations = [
// ---------------------------------- // ----------------------------------
// list // list
// ---------------------------------- // ----------------------------------
{ {
displayName: "Operation", displayName: 'Operation',
name: "operation", name: 'operation',
type: "options", type: 'options',
displayOptions: { displayOptions: {
show: { show: {
resource: ["list"] resource: [
} 'list',
],
},
}, },
options: [ options: [
{ {
name: "Archive", name: 'Archive',
value: "archive", value: 'archive',
description: "Archive/Unarchive a list" description: 'Archive/Unarchive a list'
}, },
{ {
name: "Create", name: 'Create',
value: "create", value: 'create',
description: "Create a new list" description: 'Create a new list'
}, },
{ {
name: "Get", name: 'Get',
value: "get", value: 'get',
description: "Get the data of a list" description: 'Get the data of a list'
}, },
{ {
name: "Update", name: 'Update',
value: "update", value: 'update',
description: "Update a list" description: 'Update a list'
} }
], ],
default: "create", default: 'create',
description: "The operation to perform." description: 'The operation to perform.'
} }
] as INodeProperties[]; ] as INodeProperties[];
@ -45,92 +49,112 @@ export const listFields = [
// list:archive // list:archive
// ---------------------------------- // ----------------------------------
{ {
displayName: "List ID", displayName: 'List ID',
name: "id", name: 'id',
type: "string", type: 'string',
default: "", default: '',
required: true, required: true,
displayOptions: { displayOptions: {
show: { show: {
operation: ["archive"], operation: [
resource: ["list"] 'archive',
} ],
resource: [
'list',
],
}, },
description: "The ID of the list to archive or unarchive." },
description: 'The ID of the list to archive or unarchive.'
}, },
{ {
displayName: "Archive", displayName: 'Archive',
name: "archive", name: 'archive',
type: "boolean", type: 'boolean',
default: false, default: false,
displayOptions: { displayOptions: {
show: { show: {
operation: ["archive"], operation: [
resource: ["list"] 'archive',
} ],
resource: [
'list',
],
}, },
description: "If the list should be archived or unarchived." },
description: 'If the list should be archived or unarchived.'
}, },
// ---------------------------------- // ----------------------------------
// list:create // list:create
// ---------------------------------- // ----------------------------------
{ {
displayName: "Board ID", displayName: 'Board ID',
name: "idBoard", name: 'idBoard',
type: "string", type: 'string',
default: "", default: '',
required: true, required: true,
displayOptions: { displayOptions: {
show: { show: {
operation: ["create"], operation: [
resource: ["list"] 'create',
} ],
resource: [
'list',
],
}, },
description: "The ID of the board the list should be created in" },
description: 'The ID of the board the list should be created in'
}, },
{ {
displayName: "Name", displayName: 'Name',
name: "name", name: 'name',
type: "string", type: 'string',
default: "", default: '',
placeholder: "My list", placeholder: 'My list',
required: true, required: true,
displayOptions: { displayOptions: {
show: { show: {
operation: ["create"], operation: [
resource: ["list"] 'create',
} ],
resource: [
'list',
],
}, },
description: "The name of the list" },
description: 'The name of the list'
}, },
{ {
displayName: "Additional Fields", displayName: 'Additional Fields',
name: "additionalFields", name: 'additionalFields',
type: "collection", type: 'collection',
placeholder: "Add Field", placeholder: 'Add Field',
displayOptions: { displayOptions: {
show: { show: {
operation: ["create"], operation: [
resource: ["list"] 'create',
} ],
resource: [
'list',
],
},
}, },
default: {}, default: {},
options: [ options: [
{ {
displayName: "List Source", displayName: 'List Source',
name: "idListSource", name: 'idListSource',
type: "string", type: 'string',
default: "", default: '',
description: "ID of the list to copy into the new list." description: 'ID of the list to copy into the new list.'
}, },
{ {
displayName: "Position", displayName: 'Position',
name: "pos", name: 'pos',
type: "string", type: 'string',
default: "bottom", default: 'bottom',
description: description:
"The position of the new list. top, bottom, or a positive float." 'The position of the new list. top, bottom, or a positive float.'
} }
] ]
}, },
@ -139,39 +163,46 @@ export const listFields = [
// list:get // list:get
// ---------------------------------- // ----------------------------------
{ {
displayName: "List ID", displayName: 'List ID',
name: "id", name: 'id',
type: "string", type: 'string',
default: "", default: '',
required: true, required: true,
displayOptions: { displayOptions: {
show: { show: {
operation: ["get"], operation: [
resource: ["list"] 'get',
} ],
resource: [
'list',
],
}, },
description: "The ID of the list to get." },
description: 'The ID of the list to get.'
}, },
{ {
displayName: "Additional Fields", displayName: 'Additional Fields',
name: "additionalFields", name: 'additionalFields',
type: "collection", type: 'collection',
placeholder: "Add Field", placeholder: 'Add Field',
displayOptions: { displayOptions: {
show: { show: {
operation: ["get"], operation: [
resource: ["list"] 'get',
} ],
resource: [
'list',
],
},
}, },
default: {}, default: {},
options: [ options: [
{ {
displayName: "Fields", displayName: 'Fields',
name: "fields", name: 'fields',
type: "string", type: 'string',
default: "all", default: 'all',
description: description: 'Fields to return. Either "all" or a comma-separated list of fields.'
'Fields to return. Either "all" or a comma-separated list of fields.'
} }
] ]
}, },
@ -180,67 +211,75 @@ export const listFields = [
// list:update // list:update
// ---------------------------------- // ----------------------------------
{ {
displayName: "List ID", displayName: 'List ID',
name: "id", name: 'id',
type: "string", type: 'string',
default: "", default: '',
required: true, required: true,
displayOptions: { displayOptions: {
show: { show: {
operation: ["update"], operation: [
resource: ["list"] 'update',
} ],
resource: [
'list',
],
}, },
description: "The ID of the list to update." },
description: 'The ID of the list to update.'
}, },
{ {
displayName: "Update Fields", displayName: 'Update Fields',
name: "updateFields", name: 'updateFields',
type: "collection", type: 'collection',
placeholder: "Add Field", placeholder: 'Add Field',
displayOptions: { displayOptions: {
show: { show: {
operation: ["update"], operation: [
resource: ["list"] 'update',
} ],
resource: [
'list',
],
},
}, },
default: {}, default: {},
options: [ options: [
{ {
displayName: "Board ID", displayName: 'Board ID',
name: "idBoard", name: 'idBoard',
type: "string", type: 'string',
default: "", default: '',
description: "ID of a board the list should be moved to." description: 'ID of a board the list should be moved to.'
}, },
{ {
displayName: "Closed", displayName: 'Closed',
name: "closed", name: 'closed',
type: "boolean", type: 'boolean',
default: false, default: false,
description: "Whether the list is closed." description: 'Whether the list is closed.'
}, },
{ {
displayName: "Name", displayName: 'Name',
name: "name", name: 'name',
type: "string", type: 'string',
default: "", default: '',
description: "New name of the list" description: 'New name of the list'
}, },
{ {
displayName: "Position", displayName: 'Position',
name: "pos", name: 'pos',
type: "string", type: 'string',
default: "bottom", default: 'bottom',
description: description:
"The position of the list. top, bottom, or a positive float." 'The position of the list. top, bottom, or a positive float.'
}, },
{ {
displayName: "Subscribed", displayName: 'Subscribed',
name: "subscribed", name: 'subscribed',
type: "boolean", type: 'boolean',
default: false, default: false,
description: "Whether the acting user is subscribed to the list." description: 'Whether the acting user is subscribed to the list.'
} }
] ]
} }

View file

@ -1,4 +1,7 @@
import { IExecuteFunctions } from "n8n-core"; import {
IExecuteFunctions,
} from 'n8n-core';
import { import {
IDataObject, IDataObject,
INodeTypeDescription, INodeTypeDescription,
@ -6,13 +9,44 @@ import {
INodeType, INodeType,
} from 'n8n-workflow'; } from 'n8n-workflow';
import { apiRequest } from "./GenericFunctions"; import {
import { attachmentOperations, attachmentFields } from './AttachmentDescription'; apiRequest,
import { boardOperations, boardFields } from './BoardDescription'; } from './GenericFunctions';
import { cardOperations, cardFields } from './CardDescription';
import { checklistOperations, checklistFields } from './ChecklistDescription'; import {
import { labelOperations, labelFields } from './LabelDescription'; attachmentOperations,
import { listOperations, listFields } from './ListDescription'; attachmentFields,
} from './AttachmentDescription';
import {
boardOperations,
boardFields,
} from './BoardDescription';
import {
cardOperations,
cardFields,
} from './CardDescription';
import {
cardCommentOperations,
cardCommentFields,
} from './CardCommentDescription';
import {
checklistOperations,
checklistFields,
} from './ChecklistDescription';
import {
labelOperations,
labelFields,
} from './LabelDescription';
import {
listOperations,
listFields,
} from './ListDescription';
export class Trello implements INodeType { export class Trello implements INodeType {
description: INodeTypeDescription = { description: INodeTypeDescription = {
@ -33,7 +67,7 @@ export class Trello implements INodeType {
{ {
name: 'trelloApi', name: 'trelloApi',
required: true, required: true,
} },
], ],
properties: [ properties: [
{ {
@ -53,6 +87,10 @@ export class Trello implements INodeType {
name: 'Card', name: 'Card',
value: 'card', value: 'card',
}, },
{
name: 'Card Comment',
value: 'cardComment',
},
{ {
name: 'Checklist', name: 'Checklist',
value: 'checklist', value: 'checklist',
@ -76,6 +114,7 @@ export class Trello implements INodeType {
...attachmentOperations, ...attachmentOperations,
...boardOperations, ...boardOperations,
...cardOperations, ...cardOperations,
...cardCommentOperations,
...checklistOperations, ...checklistOperations,
...labelOperations, ...labelOperations,
...listOperations, ...listOperations,
@ -86,15 +125,14 @@ export class Trello implements INodeType {
...attachmentFields, ...attachmentFields,
...boardFields, ...boardFields,
...cardFields, ...cardFields,
...cardCommentFields,
...checklistFields, ...checklistFields,
...labelFields, ...labelFields,
...listFields ...listFields
], ],
}; };
async execute(this: IExecuteFunctions): Promise<INodeExecutionData[][]> { async execute(this: IExecuteFunctions): Promise<INodeExecutionData[][]> {
const items = this.getInputData(); const items = this.getInputData();
const returnData: IDataObject[] = []; const returnData: IDataObject[] = [];
@ -236,6 +274,54 @@ export class Trello implements INodeType {
throw new Error(`The operation "${operation}" is not known!`); throw new Error(`The operation "${operation}" is not known!`);
} }
} else if (resource === 'cardComment') {
if (operation === 'add') {
// ----------------------------------
// add
// ----------------------------------
const cardId = this.getNodeParameter('cardId', i) as string;
qs.text = this.getNodeParameter('text', i) as string;
requestMethod = 'POST';
endpoint = `cards/${cardId}/actions/comments`;
} else if (operation === 'remove') {
// ----------------------------------
// delete
// ----------------------------------
requestMethod = 'DELETE';
const cardId = this.getNodeParameter('cardId', i) as string;
const commentId = this.getNodeParameter('commentId', i) as string;
endpoint = `/cards/${cardId}/actions/${commentId}/comments`;
} else if (operation === 'update') {
// ----------------------------------
// update
// ----------------------------------
requestMethod = 'PUT';
const cardId = this.getNodeParameter('cardId', i) as string;
const commentId = this.getNodeParameter('commentId', i) as string;
qs.text = this.getNodeParameter('text', i) as string;
endpoint = `cards/${cardId}/actions/${commentId}/comments`;
} else {
throw new Error(`The operation "${operation}" is not known!`);
}
} else if (resource === 'list') { } else if (resource === 'list') {
if (operation === 'archive') { if (operation === 'archive') {