Add Trello List getAll/getCards functionality (#1350)

* Fix to add List.getCards

*  Small improvements to #1347

*  Minor formatting improvements

*  Small fix

Co-authored-by: tumf <y.takahara@gmail.com>
Co-authored-by: Jan Oberhauser <jan.oberhauser@gmail.com>
This commit is contained in:
Ricardo Espinoza
2021-01-19 09:09:03 -05:00
committed by GitHub
parent 9911348166
commit 4336088741
5 changed files with 283 additions and 4 deletions

View File

@@ -11,6 +11,7 @@ import {
import {
apiRequest,
apiRequestAllItems,
} from './GenericFunctions';
import {
@@ -52,14 +53,14 @@ export class Trello implements INodeType {
description: INodeTypeDescription = {
displayName: 'Trello',
name: 'trello',
icon: 'file:trello.png',
icon: 'file:trello.svg',
group: ['transform'],
version: 1,
subtitle: '={{$parameter["operation"] + ": " + $parameter["resource"]}}',
description: 'Create, change and delete boards and cards',
defaults: {
name: 'Trello',
color: '#026aa7',
color: '#0079bf',
},
inputs: ['main'],
outputs: ['main'],
@@ -147,6 +148,8 @@ export class Trello implements INodeType {
let requestMethod: string;
let endpoint: string;
let returnAll = false;
let responseData;
for (let i = 0; i < items.length; i++) {
requestMethod = 'GET';
@@ -365,6 +368,46 @@ export class Trello implements INodeType {
const additionalFields = this.getNodeParameter('additionalFields', i) as IDataObject;
Object.assign(qs, additionalFields);
} else if (operation === 'getAll') {
// ----------------------------------
// getAll
// ----------------------------------
requestMethod = 'GET';
returnAll = this.getNodeParameter('returnAll', i) as boolean;
if (returnAll === false) {
qs.limit = this.getNodeParameter('limit', i) as number;
}
const id = this.getNodeParameter('id', i) as string;
endpoint = `boards/${id}/lists`;
const additionalFields = this.getNodeParameter('additionalFields', i) as IDataObject;
Object.assign(qs, additionalFields);
} else if (operation === 'getCards') {
// ----------------------------------
// getCards
// ----------------------------------
requestMethod = 'GET';
returnAll = this.getNodeParameter('returnAll', i) as boolean;
if (returnAll === false) {
qs.limit = this.getNodeParameter('limit', i) as number;
}
const id = this.getNodeParameter('id', i) as string;
endpoint = `lists/${id}/cards`;
const additionalFields = this.getNodeParameter('additionalFields', i) as IDataObject;
Object.assign(qs, additionalFields);
} else if (operation === 'update') {
// ----------------------------------
// update
@@ -549,7 +592,7 @@ export class Trello implements INodeType {
const additionalFields = this.getNodeParameter('additionalFields', i) as IDataObject;
Object.assign(qs, additionalFields);
} else if (operation ==='completedCheckItems') {
} else if (operation === 'completedCheckItems') {
// ----------------------------------
// completedCheckItems
// ----------------------------------
@@ -673,7 +716,21 @@ export class Trello implements INodeType {
throw new Error(`The resource "${resource}" is not known!`);
}
const responseData = await apiRequest.call(this, requestMethod, endpoint, body, qs);
// resources listed here do not support pagination so
// paginate them 'manually'
const skipPagination = [
'list:getAll',
];
if (returnAll === true && !skipPagination.includes(`${resource}:${operation}`)) {
responseData = await apiRequestAllItems.call(this, requestMethod, endpoint, body, qs);
} else {
responseData = await apiRequest.call(this, requestMethod, endpoint, body, qs);
if (returnAll === false && qs.limit) {
responseData = responseData.splice(0, qs.limit);
}
}
if (Array.isArray(responseData)) {
returnData.push.apply(returnData, responseData as IDataObject[]);