2023-01-27 03:22:44 -08:00
|
|
|
import type {
|
2023-03-09 09:13:15 -08:00
|
|
|
IExecuteFunctions,
|
2020-10-13 04:00:14 -07:00
|
|
|
IDataObject,
|
|
|
|
ILoadOptionsFunctions,
|
|
|
|
INodeExecutionData,
|
|
|
|
INodePropertyOptions,
|
|
|
|
INodeType,
|
|
|
|
INodeTypeDescription,
|
2024-02-14 07:29:09 -08:00
|
|
|
IHttpRequestMethods,
|
2020-10-13 04:00:14 -07:00
|
|
|
} from 'n8n-workflow';
|
2023-01-27 03:22:44 -08:00
|
|
|
import { NodeOperationError } from 'n8n-workflow';
|
2020-10-13 04:00:14 -07:00
|
|
|
|
2023-10-10 08:36:20 -07:00
|
|
|
import { wrapData } from '../../utils/utilities';
|
2022-08-17 08:50:24 -07:00
|
|
|
import { apiRequest } from './GenericFunctions';
|
2020-10-13 04:00:14 -07:00
|
|
|
|
2022-08-17 08:50:24 -07:00
|
|
|
import { boardFields, boardOperations } from './BoardDescription';
|
2020-10-13 04:00:14 -07:00
|
|
|
|
2022-08-17 08:50:24 -07:00
|
|
|
import { cardFields, cardOperations } from './CardDescription';
|
2020-10-13 04:00:14 -07:00
|
|
|
|
2022-08-17 08:50:24 -07:00
|
|
|
import { cardCommentFields, cardCommentOperations } from './CardCommentDescription';
|
2020-10-13 04:00:14 -07:00
|
|
|
|
2022-08-17 08:50:24 -07:00
|
|
|
import { checklistFields, checklistOperations } from './ChecklistDescription';
|
2020-10-13 04:00:14 -07:00
|
|
|
|
2022-08-17 08:50:24 -07:00
|
|
|
import { checklistItemFields, checklistItemOperations } from './ChecklistItemDescription';
|
2020-10-13 04:00:14 -07:00
|
|
|
|
2022-08-17 08:50:24 -07:00
|
|
|
import { listFields, listOperations } from './ListDescription';
|
2020-10-13 04:00:14 -07:00
|
|
|
|
|
|
|
// https://wekan.github.io/api/v4.41/
|
|
|
|
|
|
|
|
export class Wekan implements INodeType {
|
|
|
|
description: INodeTypeDescription = {
|
|
|
|
displayName: 'Wekan',
|
|
|
|
name: 'wekan',
|
2022-06-20 07:54:01 -07:00
|
|
|
// eslint-disable-next-line n8n-nodes-base/node-class-description-icon-not-svg
|
2020-10-13 04:00:14 -07:00
|
|
|
icon: 'file:wekan.png',
|
|
|
|
group: ['transform'],
|
|
|
|
version: 1,
|
|
|
|
subtitle: '={{$parameter["operation"] + ": " + $parameter["resource"]}}',
|
2021-07-03 05:40:16 -07:00
|
|
|
description: 'Consume Wekan API',
|
2020-10-13 04:00:14 -07:00
|
|
|
defaults: {
|
|
|
|
name: 'Wekan',
|
|
|
|
},
|
|
|
|
inputs: ['main'],
|
|
|
|
outputs: ['main'],
|
|
|
|
credentials: [
|
|
|
|
{
|
|
|
|
name: 'wekanApi',
|
|
|
|
required: true,
|
|
|
|
},
|
|
|
|
],
|
|
|
|
properties: [
|
|
|
|
{
|
|
|
|
displayName: 'Resource',
|
|
|
|
name: 'resource',
|
|
|
|
type: 'options',
|
2022-05-20 14:47:24 -07:00
|
|
|
noDataExpression: true,
|
2020-10-13 04:00:14 -07:00
|
|
|
options: [
|
|
|
|
{
|
|
|
|
name: 'Board',
|
|
|
|
value: 'board',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'Card',
|
|
|
|
value: 'card',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'Card Comment',
|
|
|
|
value: 'cardComment',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'Checklist',
|
|
|
|
value: 'checklist',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'Checklist Item',
|
|
|
|
value: 'checklistItem',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'List',
|
|
|
|
value: 'list',
|
|
|
|
},
|
|
|
|
],
|
|
|
|
default: 'card',
|
|
|
|
},
|
|
|
|
|
|
|
|
// ----------------------------------
|
|
|
|
// operations
|
|
|
|
// ----------------------------------
|
|
|
|
...boardOperations,
|
|
|
|
...cardOperations,
|
|
|
|
...cardCommentOperations,
|
|
|
|
...checklistOperations,
|
|
|
|
...checklistItemOperations,
|
|
|
|
...listOperations,
|
|
|
|
|
|
|
|
// ----------------------------------
|
|
|
|
// fields
|
|
|
|
// ----------------------------------
|
|
|
|
...boardFields,
|
|
|
|
...cardFields,
|
|
|
|
...cardCommentFields,
|
|
|
|
...checklistFields,
|
|
|
|
...checklistItemFields,
|
|
|
|
...listFields,
|
|
|
|
],
|
|
|
|
};
|
|
|
|
|
|
|
|
methods = {
|
|
|
|
loadOptions: {
|
|
|
|
async getUsers(this: ILoadOptionsFunctions): Promise<INodePropertyOptions[]> {
|
|
|
|
const returnData: INodePropertyOptions[] = [];
|
|
|
|
const users = await apiRequest.call(this, 'GET', 'users', {}, {});
|
|
|
|
for (const user of users) {
|
|
|
|
returnData.push({
|
|
|
|
name: user.username,
|
|
|
|
value: user._id,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
return returnData;
|
|
|
|
},
|
|
|
|
async getBoards(this: ILoadOptionsFunctions): Promise<INodePropertyOptions[]> {
|
|
|
|
const returnData: INodePropertyOptions[] = [];
|
2022-12-29 03:20:43 -08:00
|
|
|
const user = await apiRequest.call(this, 'GET', 'user', {}, {});
|
2020-10-13 04:00:14 -07:00
|
|
|
const boards = await apiRequest.call(this, 'GET', `users/${user._id}/boards`, {}, {});
|
|
|
|
for (const board of boards) {
|
|
|
|
returnData.push({
|
|
|
|
name: board.title,
|
|
|
|
value: board._id,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
return returnData;
|
|
|
|
},
|
|
|
|
async getLists(this: ILoadOptionsFunctions): Promise<INodePropertyOptions[]> {
|
|
|
|
const returnData: INodePropertyOptions[] = [];
|
|
|
|
const boardId = this.getCurrentNodeParameter('boardId') as string;
|
|
|
|
const lists = await apiRequest.call(this, 'GET', `boards/${boardId}/lists`, {}, {});
|
|
|
|
for (const list of lists) {
|
|
|
|
returnData.push({
|
|
|
|
name: list.title,
|
|
|
|
value: list._id,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
return returnData;
|
|
|
|
},
|
|
|
|
async getSwimlanes(this: ILoadOptionsFunctions): Promise<INodePropertyOptions[]> {
|
|
|
|
const returnData: INodePropertyOptions[] = [];
|
|
|
|
const boardId = this.getCurrentNodeParameter('boardId') as string;
|
|
|
|
const swimlanes = await apiRequest.call(this, 'GET', `boards/${boardId}/swimlanes`, {}, {});
|
|
|
|
for (const swimlane of swimlanes) {
|
|
|
|
returnData.push({
|
|
|
|
name: swimlane.title,
|
|
|
|
value: swimlane._id,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
return returnData;
|
|
|
|
},
|
|
|
|
async getCards(this: ILoadOptionsFunctions): Promise<INodePropertyOptions[]> {
|
|
|
|
const returnData: INodePropertyOptions[] = [];
|
|
|
|
const boardId = this.getCurrentNodeParameter('boardId') as string;
|
|
|
|
const listId = this.getCurrentNodeParameter('listId') as string;
|
2022-08-17 08:50:24 -07:00
|
|
|
const cards = await apiRequest.call(
|
|
|
|
this,
|
|
|
|
'GET',
|
|
|
|
`boards/${boardId}/lists/${listId}/cards`,
|
|
|
|
{},
|
|
|
|
{},
|
|
|
|
);
|
2020-10-13 04:00:14 -07:00
|
|
|
for (const card of cards) {
|
|
|
|
returnData.push({
|
|
|
|
name: card.title,
|
|
|
|
value: card._id,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
return returnData;
|
|
|
|
},
|
|
|
|
async getChecklists(this: ILoadOptionsFunctions): Promise<INodePropertyOptions[]> {
|
|
|
|
const returnData: INodePropertyOptions[] = [];
|
|
|
|
const boardId = this.getCurrentNodeParameter('boardId') as string;
|
|
|
|
const cardId = this.getCurrentNodeParameter('cardId') as string;
|
2022-08-17 08:50:24 -07:00
|
|
|
const checklists = await apiRequest.call(
|
|
|
|
this,
|
|
|
|
'GET',
|
|
|
|
`boards/${boardId}/cards/${cardId}/checklists`,
|
|
|
|
{},
|
|
|
|
{},
|
|
|
|
);
|
2020-10-13 04:00:14 -07:00
|
|
|
for (const checklist of checklists) {
|
|
|
|
returnData.push({
|
|
|
|
name: checklist.title,
|
|
|
|
value: checklist._id,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
return returnData;
|
|
|
|
},
|
|
|
|
async getChecklistItems(this: ILoadOptionsFunctions): Promise<INodePropertyOptions[]> {
|
|
|
|
const returnData: INodePropertyOptions[] = [];
|
|
|
|
const boardId = this.getCurrentNodeParameter('boardId') as string;
|
|
|
|
const cardId = this.getCurrentNodeParameter('cardId') as string;
|
|
|
|
const checklistId = this.getCurrentNodeParameter('checklistId') as string;
|
2022-08-17 08:50:24 -07:00
|
|
|
const checklist = await apiRequest.call(
|
|
|
|
this,
|
|
|
|
'GET',
|
|
|
|
`boards/${boardId}/cards/${cardId}/checklists/${checklistId}`,
|
|
|
|
{},
|
|
|
|
{},
|
|
|
|
);
|
2020-10-13 04:00:14 -07:00
|
|
|
for (const item of checklist.items) {
|
|
|
|
returnData.push({
|
|
|
|
name: item.title,
|
|
|
|
value: item._id,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
return returnData;
|
|
|
|
},
|
|
|
|
async getComments(this: ILoadOptionsFunctions): Promise<INodePropertyOptions[]> {
|
|
|
|
const returnData: INodePropertyOptions[] = [];
|
|
|
|
const boardId = this.getCurrentNodeParameter('boardId') as string;
|
|
|
|
const cardId = this.getCurrentNodeParameter('cardId') as string;
|
2022-08-17 08:50:24 -07:00
|
|
|
const comments = await apiRequest.call(
|
|
|
|
this,
|
|
|
|
'GET',
|
|
|
|
`boards/${boardId}/cards/${cardId}/comments`,
|
|
|
|
{},
|
|
|
|
{},
|
|
|
|
);
|
2020-10-13 04:00:14 -07:00
|
|
|
for (const comment of comments) {
|
|
|
|
returnData.push({
|
|
|
|
name: comment.comment,
|
|
|
|
value: comment._id,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
return returnData;
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
async execute(this: IExecuteFunctions): Promise<INodeExecutionData[][]> {
|
|
|
|
const items = this.getInputData();
|
2023-10-10 08:36:20 -07:00
|
|
|
const returnData: INodeExecutionData[] = [];
|
2020-10-13 04:00:14 -07:00
|
|
|
let returnAll;
|
|
|
|
let limit;
|
|
|
|
|
2022-12-02 03:53:59 -08:00
|
|
|
const operation = this.getNodeParameter('operation', 0);
|
|
|
|
const resource = this.getNodeParameter('resource', 0);
|
2020-10-13 04:00:14 -07:00
|
|
|
|
|
|
|
// For Post
|
|
|
|
let body: IDataObject;
|
|
|
|
// For Query string
|
|
|
|
let qs: IDataObject;
|
|
|
|
|
2024-02-14 07:29:09 -08:00
|
|
|
let requestMethod: IHttpRequestMethods;
|
2020-10-13 04:00:14 -07:00
|
|
|
let endpoint: string;
|
|
|
|
|
|
|
|
for (let i = 0; i < items.length; i++) {
|
2021-07-19 23:58:54 -07:00
|
|
|
try {
|
|
|
|
requestMethod = 'GET';
|
|
|
|
endpoint = '';
|
|
|
|
body = {};
|
|
|
|
qs = {};
|
2020-10-13 04:00:14 -07:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
if (resource === 'board') {
|
|
|
|
if (operation === 'create') {
|
|
|
|
// ----------------------------------
|
|
|
|
// create
|
|
|
|
// ----------------------------------
|
2020-10-13 04:00:14 -07:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
requestMethod = 'POST';
|
|
|
|
endpoint = 'boards';
|
2020-10-13 04:00:14 -07:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
body.title = this.getNodeParameter('title', i) as string;
|
|
|
|
body.owner = this.getNodeParameter('owner', i) as string;
|
2020-10-13 04:00:14 -07:00
|
|
|
|
2022-11-18 07:29:44 -08:00
|
|
|
const additionalFields = this.getNodeParameter('additionalFields', i);
|
2021-07-19 23:58:54 -07:00
|
|
|
Object.assign(body, additionalFields);
|
|
|
|
} else if (operation === 'delete') {
|
|
|
|
// ----------------------------------
|
|
|
|
// delete
|
|
|
|
// ----------------------------------
|
2020-10-13 04:00:14 -07:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
requestMethod = 'DELETE';
|
2020-10-13 04:00:14 -07:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
const boardId = this.getNodeParameter('boardId', i) as string;
|
2020-10-13 04:00:14 -07:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
endpoint = `boards/${boardId}`;
|
|
|
|
} else if (operation === 'get') {
|
|
|
|
// ----------------------------------
|
|
|
|
// get
|
|
|
|
// ----------------------------------
|
2020-10-13 04:00:14 -07:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
requestMethod = 'GET';
|
2020-10-13 04:00:14 -07:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
const boardId = this.getNodeParameter('boardId', i) as string;
|
2020-10-13 04:00:14 -07:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
endpoint = `boards/${boardId}`;
|
|
|
|
} else if (operation === 'getAll') {
|
|
|
|
// ----------------------------------
|
|
|
|
// getAll
|
|
|
|
// ----------------------------------
|
2020-10-13 04:00:14 -07:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
requestMethod = 'GET';
|
2020-10-13 04:00:14 -07:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
const userId = this.getNodeParameter('IdUser', i) as string;
|
2020-10-13 04:00:14 -07:00
|
|
|
|
2022-11-18 05:31:38 -08:00
|
|
|
returnAll = this.getNodeParameter('returnAll', i);
|
2020-10-13 04:00:14 -07:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
endpoint = `users/${userId}/boards`;
|
|
|
|
} else {
|
2022-08-17 08:50:24 -07:00
|
|
|
throw new NodeOperationError(
|
|
|
|
this.getNode(),
|
|
|
|
`The operation "${operation}" is not known!`,
|
|
|
|
{ itemIndex: i },
|
|
|
|
);
|
2021-07-19 23:58:54 -07:00
|
|
|
}
|
|
|
|
} else if (resource === 'card') {
|
|
|
|
if (operation === 'create') {
|
|
|
|
// ----------------------------------
|
|
|
|
// create
|
|
|
|
// ----------------------------------
|
2020-10-13 04:00:14 -07:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
requestMethod = 'POST';
|
2020-10-13 04:00:14 -07:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
const boardId = this.getNodeParameter('boardId', i) as string;
|
|
|
|
const listId = this.getNodeParameter('listId', i) as string;
|
2020-10-13 04:00:14 -07:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
endpoint = `boards/${boardId}/lists/${listId}/cards`;
|
2020-10-13 04:00:14 -07:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
body.title = this.getNodeParameter('title', i) as string;
|
|
|
|
body.swimlaneId = this.getNodeParameter('swimlaneId', i) as string;
|
|
|
|
body.authorId = this.getNodeParameter('authorId', i) as string;
|
2020-10-13 04:00:14 -07:00
|
|
|
|
2022-11-18 07:29:44 -08:00
|
|
|
const additionalFields = this.getNodeParameter('additionalFields', i);
|
2021-07-19 23:58:54 -07:00
|
|
|
Object.assign(body, additionalFields);
|
|
|
|
} else if (operation === 'delete') {
|
|
|
|
// ----------------------------------
|
|
|
|
// delete
|
|
|
|
// ----------------------------------
|
2020-10-13 04:00:14 -07:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
requestMethod = 'DELETE';
|
2020-10-13 04:00:14 -07:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
const boardId = this.getNodeParameter('boardId', i) as string;
|
|
|
|
const listId = this.getNodeParameter('listId', i) as string;
|
|
|
|
const cardId = this.getNodeParameter('cardId', i) as string;
|
2020-10-13 04:00:14 -07:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
endpoint = `boards/${boardId}/lists/${listId}/cards/${cardId}`;
|
|
|
|
} else if (operation === 'get') {
|
|
|
|
// ----------------------------------
|
|
|
|
// get
|
|
|
|
// ----------------------------------
|
2020-10-13 04:00:14 -07:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
requestMethod = 'GET';
|
2020-10-13 04:00:14 -07:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
const boardId = this.getNodeParameter('boardId', i) as string;
|
|
|
|
const listId = this.getNodeParameter('listId', i) as string;
|
|
|
|
const cardId = this.getNodeParameter('cardId', i) as string;
|
2020-10-13 04:00:14 -07:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
endpoint = `boards/${boardId}/lists/${listId}/cards/${cardId}`;
|
|
|
|
} else if (operation === 'getAll') {
|
|
|
|
// ----------------------------------
|
|
|
|
// getAll
|
|
|
|
// ----------------------------------
|
2020-10-13 04:00:14 -07:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
requestMethod = 'GET';
|
2020-10-13 04:00:14 -07:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
const boardId = this.getNodeParameter('boardId', i) as string;
|
|
|
|
const fromObject = this.getNodeParameter('fromObject', i) as string;
|
2022-11-18 05:31:38 -08:00
|
|
|
returnAll = this.getNodeParameter('returnAll', i);
|
2020-10-13 04:00:14 -07:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
if (fromObject === 'list') {
|
|
|
|
const listId = this.getNodeParameter('listId', i) as string;
|
2020-10-13 04:00:14 -07:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
endpoint = `boards/${boardId}/lists/${listId}/cards`;
|
|
|
|
}
|
2020-10-13 04:00:14 -07:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
if (fromObject === 'swimlane') {
|
|
|
|
const swimlaneId = this.getNodeParameter('swimlaneId', i) as string;
|
2020-10-13 04:00:14 -07:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
endpoint = `boards/${boardId}/swimlanes/${swimlaneId}/cards`;
|
|
|
|
}
|
|
|
|
} else if (operation === 'update') {
|
|
|
|
// ----------------------------------
|
|
|
|
// update
|
|
|
|
// ----------------------------------
|
2020-10-13 04:00:14 -07:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
requestMethod = 'PUT';
|
2020-10-13 04:00:14 -07:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
const boardId = this.getNodeParameter('boardId', i) as string;
|
|
|
|
const listId = this.getNodeParameter('listId', i) as string;
|
|
|
|
const cardId = this.getNodeParameter('cardId', i) as string;
|
2020-10-13 04:00:14 -07:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
endpoint = `boards/${boardId}/lists/${listId}/cards/${cardId}`;
|
2020-10-13 04:00:14 -07:00
|
|
|
|
2022-11-18 07:29:44 -08:00
|
|
|
const updateFields = this.getNodeParameter('updateFields', i);
|
2021-07-19 23:58:54 -07:00
|
|
|
Object.assign(body, updateFields);
|
|
|
|
} else {
|
2022-08-17 08:50:24 -07:00
|
|
|
throw new NodeOperationError(
|
|
|
|
this.getNode(),
|
|
|
|
`The operation "${operation}" is not known!`,
|
|
|
|
{ itemIndex: i },
|
|
|
|
);
|
2021-07-19 23:58:54 -07:00
|
|
|
}
|
|
|
|
} else if (resource === 'cardComment') {
|
|
|
|
if (operation === 'create') {
|
|
|
|
// ----------------------------------
|
|
|
|
// create
|
|
|
|
// ----------------------------------
|
2020-10-13 04:00:14 -07:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
requestMethod = 'POST';
|
2020-10-13 04:00:14 -07:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
const boardId = this.getNodeParameter('boardId', i) as string;
|
|
|
|
const cardId = this.getNodeParameter('cardId', i) as string;
|
2020-10-13 04:00:14 -07:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
endpoint = `boards/${boardId}/cards/${cardId}/comments`;
|
2020-10-13 04:00:14 -07:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
body.authorId = this.getNodeParameter('authorId', i) as string;
|
|
|
|
body.comment = this.getNodeParameter('comment', i) as string;
|
|
|
|
} else if (operation === 'delete') {
|
|
|
|
// ----------------------------------
|
|
|
|
// delete
|
|
|
|
// ----------------------------------
|
2020-10-13 04:00:14 -07:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
requestMethod = 'DELETE';
|
2020-10-13 04:00:14 -07:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
const boardId = this.getNodeParameter('boardId', i) as string;
|
|
|
|
const cardId = this.getNodeParameter('cardId', i) as string;
|
|
|
|
const commentId = this.getNodeParameter('commentId', i) as string;
|
2020-10-13 04:00:14 -07:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
endpoint = `boards/${boardId}/cards/${cardId}/comments/${commentId}`;
|
|
|
|
} else if (operation === 'get') {
|
|
|
|
// ----------------------------------
|
|
|
|
// get
|
|
|
|
// ----------------------------------
|
2020-10-13 04:00:14 -07:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
requestMethod = 'GET';
|
2020-10-13 04:00:14 -07:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
const boardId = this.getNodeParameter('boardId', i) as string;
|
|
|
|
const cardId = this.getNodeParameter('cardId', i) as string;
|
|
|
|
const commentId = this.getNodeParameter('commentId', i) as string;
|
2020-10-13 04:00:14 -07:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
endpoint = `boards/${boardId}/cards/${cardId}/comments/${commentId}`;
|
|
|
|
} else if (operation === 'getAll') {
|
|
|
|
// ----------------------------------
|
|
|
|
// getAll
|
|
|
|
// ----------------------------------
|
2020-10-13 04:00:14 -07:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
requestMethod = 'GET';
|
2020-10-13 04:00:14 -07:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
const boardId = this.getNodeParameter('boardId', i) as string;
|
|
|
|
const cardId = this.getNodeParameter('cardId', i) as string;
|
2020-10-13 04:00:14 -07:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
endpoint = `boards/${boardId}/cards/${cardId}/comments`;
|
|
|
|
} else {
|
2022-08-17 08:50:24 -07:00
|
|
|
throw new NodeOperationError(
|
|
|
|
this.getNode(),
|
|
|
|
`The operation "${operation}" is not known!`,
|
|
|
|
{ itemIndex: i },
|
|
|
|
);
|
2021-07-19 23:58:54 -07:00
|
|
|
}
|
|
|
|
} else if (resource === 'list') {
|
|
|
|
if (operation === 'create') {
|
|
|
|
// ----------------------------------
|
|
|
|
// create
|
|
|
|
// ----------------------------------
|
2020-10-13 04:00:14 -07:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
requestMethod = 'POST';
|
2020-10-13 04:00:14 -07:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
const boardId = this.getNodeParameter('boardId', i) as string;
|
2020-10-13 04:00:14 -07:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
endpoint = `boards/${boardId}/lists`;
|
2020-10-13 04:00:14 -07:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
body.title = this.getNodeParameter('title', i) as string;
|
|
|
|
} else if (operation === 'delete') {
|
|
|
|
// ----------------------------------
|
|
|
|
// delete
|
|
|
|
// ----------------------------------
|
2020-10-13 04:00:14 -07:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
requestMethod = 'DELETE';
|
2020-10-13 04:00:14 -07:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
const boardId = this.getNodeParameter('boardId', i) as string;
|
|
|
|
const listId = this.getNodeParameter('listId', i) as string;
|
2020-10-13 04:00:14 -07:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
endpoint = `boards/${boardId}/lists/${listId}`;
|
|
|
|
} else if (operation === 'get') {
|
|
|
|
// ----------------------------------
|
|
|
|
// get
|
|
|
|
// ----------------------------------
|
2020-10-13 04:00:14 -07:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
requestMethod = 'GET';
|
2020-10-13 04:00:14 -07:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
const boardId = this.getNodeParameter('boardId', i) as string;
|
|
|
|
const listId = this.getNodeParameter('listId', i) as string;
|
2020-10-13 04:00:14 -07:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
endpoint = `boards/${boardId}/lists/${listId}`;
|
|
|
|
} else if (operation === 'getAll') {
|
|
|
|
// ----------------------------------
|
|
|
|
// getAll
|
|
|
|
// ----------------------------------
|
2020-10-13 04:00:14 -07:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
requestMethod = 'GET';
|
2020-10-13 04:00:14 -07:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
const boardId = this.getNodeParameter('boardId', i) as string;
|
2022-11-18 05:31:38 -08:00
|
|
|
returnAll = this.getNodeParameter('returnAll', i);
|
2020-10-13 04:00:14 -07:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
endpoint = `boards/${boardId}/lists`;
|
|
|
|
} else {
|
2022-08-17 08:50:24 -07:00
|
|
|
throw new NodeOperationError(
|
|
|
|
this.getNode(),
|
|
|
|
`The operation "${operation}" is not known!`,
|
|
|
|
{ itemIndex: i },
|
|
|
|
);
|
2021-07-19 23:58:54 -07:00
|
|
|
}
|
|
|
|
} else if (resource === 'checklist') {
|
|
|
|
if (operation === 'create') {
|
|
|
|
// ----------------------------------
|
|
|
|
// create
|
|
|
|
// ----------------------------------
|
2020-10-13 04:00:14 -07:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
requestMethod = 'POST';
|
2020-10-13 04:00:14 -07:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
const boardId = this.getNodeParameter('boardId', i) as string;
|
|
|
|
const cardId = this.getNodeParameter('cardId', i) as string;
|
2020-10-13 04:00:14 -07:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
endpoint = `boards/${boardId}/cards/${cardId}/checklists`;
|
2020-10-13 04:00:14 -07:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
body.title = this.getNodeParameter('title', i) as string;
|
2020-10-13 04:00:14 -07:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
body.items = this.getNodeParameter('items', i) as string[];
|
|
|
|
} else if (operation === 'delete') {
|
|
|
|
// ----------------------------------
|
|
|
|
// delete
|
|
|
|
// ----------------------------------
|
2020-10-13 04:00:14 -07:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
requestMethod = 'DELETE';
|
2020-10-13 04:00:14 -07:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
const boardId = this.getNodeParameter('boardId', i) as string;
|
|
|
|
const cardId = this.getNodeParameter('cardId', i) as string;
|
|
|
|
const checklistId = this.getNodeParameter('checklistId', i) as string;
|
2020-10-13 04:00:14 -07:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
endpoint = `boards/${boardId}/cards/${cardId}/checklists/${checklistId}`;
|
|
|
|
} else if (operation === 'get') {
|
|
|
|
// ----------------------------------
|
|
|
|
// get
|
|
|
|
// ----------------------------------
|
2020-10-13 04:00:14 -07:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
requestMethod = 'GET';
|
2020-10-13 04:00:14 -07:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
const boardId = this.getNodeParameter('boardId', i) as string;
|
|
|
|
const cardId = this.getNodeParameter('cardId', i) as string;
|
|
|
|
const checklistId = this.getNodeParameter('checklistId', i) as string;
|
2020-10-13 04:00:14 -07:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
endpoint = `boards/${boardId}/cards/${cardId}/checklists/${checklistId}`;
|
|
|
|
} else if (operation === 'getAll') {
|
|
|
|
// ----------------------------------
|
|
|
|
// getAll
|
|
|
|
// ----------------------------------
|
2020-10-13 04:00:14 -07:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
requestMethod = 'GET';
|
2020-10-13 04:00:14 -07:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
const boardId = this.getNodeParameter('boardId', i) as string;
|
|
|
|
const cardId = this.getNodeParameter('cardId', i) as string;
|
2022-11-18 05:31:38 -08:00
|
|
|
returnAll = this.getNodeParameter('returnAll', i);
|
2020-10-13 04:00:14 -07:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
endpoint = `boards/${boardId}/cards/${cardId}/checklists`;
|
|
|
|
} else if (operation === 'getCheckItem') {
|
|
|
|
// ----------------------------------
|
|
|
|
// getCheckItem
|
|
|
|
// ----------------------------------
|
2020-10-13 04:00:14 -07:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
requestMethod = 'GET';
|
2020-10-13 04:00:14 -07:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
const boardId = this.getNodeParameter('boardId', i) as string;
|
|
|
|
const cardId = this.getNodeParameter('cardId', i) as string;
|
|
|
|
const checklistId = this.getNodeParameter('checklistId', i) as string;
|
|
|
|
const itemId = this.getNodeParameter('itemId', i) as string;
|
2020-10-13 04:00:14 -07:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
endpoint = `boards/${boardId}/cards/${cardId}/checklists/${checklistId}/items/${itemId}`;
|
|
|
|
} else if (operation === 'deleteCheckItem') {
|
|
|
|
// ----------------------------------
|
|
|
|
// deleteCheckItem
|
|
|
|
// ----------------------------------
|
2020-10-13 04:00:14 -07:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
requestMethod = 'DELETE';
|
2020-10-13 04:00:14 -07:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
const boardId = this.getNodeParameter('boardId', i) as string;
|
|
|
|
const cardId = this.getNodeParameter('cardId', i) as string;
|
|
|
|
const checklistId = this.getNodeParameter('checklistId', i) as string;
|
|
|
|
const itemId = this.getNodeParameter('itemId', i) as string;
|
2020-10-13 04:00:14 -07:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
endpoint = `boards/${boardId}/cards/${cardId}/checklists/${checklistId}/items/${itemId}`;
|
|
|
|
} else if (operation === 'updateCheckItem') {
|
|
|
|
// ----------------------------------
|
|
|
|
// updateCheckItem
|
|
|
|
// ----------------------------------
|
2020-10-13 04:00:14 -07:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
requestMethod = 'PUT';
|
2020-10-13 04:00:14 -07:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
const boardId = this.getNodeParameter('boardId', i) as string;
|
|
|
|
const cardId = this.getNodeParameter('cardId', i) as string;
|
|
|
|
const checklistId = this.getNodeParameter('checklistId', i) as string;
|
|
|
|
const itemId = this.getNodeParameter('itemId', i) as string;
|
2020-10-13 04:00:14 -07:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
endpoint = `boards/${boardId}/cards/${cardId}/checklists/${checklistId}/items/${itemId}`;
|
2020-10-13 04:00:14 -07:00
|
|
|
|
2022-11-18 07:29:44 -08:00
|
|
|
const updateFields = this.getNodeParameter('updateFields', i);
|
2021-07-19 23:58:54 -07:00
|
|
|
Object.assign(body, updateFields);
|
|
|
|
} else {
|
2022-08-17 08:50:24 -07:00
|
|
|
throw new NodeOperationError(
|
|
|
|
this.getNode(),
|
|
|
|
`The operation "${operation}" is not known!`,
|
|
|
|
{ itemIndex: i },
|
|
|
|
);
|
2021-07-19 23:58:54 -07:00
|
|
|
}
|
|
|
|
} else if (resource === 'checklistItem') {
|
|
|
|
if (operation === 'get') {
|
|
|
|
// ----------------------------------
|
|
|
|
// get
|
|
|
|
// ----------------------------------
|
2020-10-13 04:00:14 -07:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
requestMethod = 'GET';
|
2020-10-13 04:00:14 -07:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
const boardId = this.getNodeParameter('boardId', i) as string;
|
|
|
|
const cardId = this.getNodeParameter('cardId', i) as string;
|
|
|
|
const checklistId = this.getNodeParameter('checklistId', i) as string;
|
|
|
|
const itemId = this.getNodeParameter('checklistItemId', i) as string;
|
2020-10-13 04:00:14 -07:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
endpoint = `boards/${boardId}/cards/${cardId}/checklists/${checklistId}/items/${itemId}`;
|
|
|
|
} else if (operation === 'delete') {
|
|
|
|
// ----------------------------------
|
|
|
|
// delete
|
|
|
|
// ----------------------------------
|
2020-10-13 04:00:14 -07:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
requestMethod = 'DELETE';
|
2020-10-13 04:00:14 -07:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
const boardId = this.getNodeParameter('boardId', i) as string;
|
|
|
|
const cardId = this.getNodeParameter('cardId', i) as string;
|
|
|
|
const checklistId = this.getNodeParameter('checklistId', i) as string;
|
|
|
|
const itemId = this.getNodeParameter('checklistItemId', i) as string;
|
2020-10-13 04:00:14 -07:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
endpoint = `boards/${boardId}/cards/${cardId}/checklists/${checklistId}/items/${itemId}`;
|
|
|
|
} else if (operation === 'update') {
|
|
|
|
// ----------------------------------
|
|
|
|
// update
|
|
|
|
// ----------------------------------
|
2020-10-13 04:00:14 -07:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
requestMethod = 'PUT';
|
2020-10-13 04:00:14 -07:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
const boardId = this.getNodeParameter('boardId', i) as string;
|
|
|
|
const cardId = this.getNodeParameter('cardId', i) as string;
|
|
|
|
const checklistId = this.getNodeParameter('checklistId', i) as string;
|
|
|
|
const itemId = this.getNodeParameter('checklistItemId', i) as string;
|
2020-10-13 04:00:14 -07:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
endpoint = `boards/${boardId}/cards/${cardId}/checklists/${checklistId}/items/${itemId}`;
|
2020-10-13 04:00:14 -07:00
|
|
|
|
2022-11-18 07:29:44 -08:00
|
|
|
const updateFields = this.getNodeParameter('updateFields', i);
|
2021-07-19 23:58:54 -07:00
|
|
|
Object.assign(body, updateFields);
|
|
|
|
}
|
2020-10-13 04:00:14 -07:00
|
|
|
}
|
2021-07-19 23:58:54 -07:00
|
|
|
let responseData = await apiRequest.call(this, requestMethod, endpoint, body, qs);
|
2020-10-13 04:00:14 -07:00
|
|
|
|
2023-05-22 09:09:10 -07:00
|
|
|
if (returnAll === false && Array.isArray(responseData)) {
|
2022-11-18 06:26:22 -08:00
|
|
|
limit = this.getNodeParameter('limit', i);
|
2021-07-19 23:58:54 -07:00
|
|
|
responseData = responseData.splice(0, limit);
|
|
|
|
}
|
2020-10-13 04:00:14 -07:00
|
|
|
|
2023-10-10 08:36:20 -07:00
|
|
|
const executionData = this.helpers.constructExecutionMetaData(
|
|
|
|
wrapData(responseData as IDataObject[]),
|
|
|
|
{ itemData: { item: i } },
|
|
|
|
);
|
|
|
|
|
|
|
|
returnData.push(...executionData);
|
2021-07-19 23:58:54 -07:00
|
|
|
} catch (error) {
|
|
|
|
if (this.continueOnFail()) {
|
2023-10-10 08:36:20 -07:00
|
|
|
returnData.push({ json: { error: error.message }, pairedItem: { item: i } });
|
2021-07-19 23:58:54 -07:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
throw error;
|
2020-10-13 04:00:14 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return [this.helpers.returnJsonArray(returnData)];
|
|
|
|
}
|
|
|
|
}
|