mirror of
https://github.com/n8n-io/n8n.git
synced 2025-03-05 20:50:17 -08:00
⚡ Todoist node enhancement (#823)
* Todoist node enhancement * done * ⚡ Improvements * 💄 Remove comment * 💄 remove unnecessary line * 📚 Add breaking change message * ⚡ Remove unnecessary line Co-authored-by: lukigarazus <ywnwa96@gmail.com>
This commit is contained in:
parent
cc32418c4f
commit
c3277df25b
|
@ -2,6 +2,26 @@
|
||||||
|
|
||||||
This list shows all the versions which include breaking changes and how to upgrade.
|
This list shows all the versions which include breaking changes and how to upgrade.
|
||||||
|
|
||||||
|
## 0.80.0
|
||||||
|
|
||||||
|
### What changed?
|
||||||
|
|
||||||
|
We have renamed the operations on the Todoist Node to keep consistency with the codebase. Also, deleted the operations close_match and delete_match as these operations can be accomplished using the operations getAll, close, and delete.
|
||||||
|
|
||||||
|
### When is action necessary?
|
||||||
|
|
||||||
|
When one of the following operations is used.
|
||||||
|
|
||||||
|
- close_by
|
||||||
|
- close_match
|
||||||
|
- delete_id
|
||||||
|
- delete_match
|
||||||
|
|
||||||
|
### How to upgrade:
|
||||||
|
|
||||||
|
After upgrading open all workflows, which contain the Todoist Node, set the corresponding operation, and then save the workflow.
|
||||||
|
|
||||||
|
If the operations close_match or delete_match are used, recreate them using the operations getAll, delete and close.
|
||||||
|
|
||||||
## 0.69.0
|
## 0.69.0
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,46 @@
|
||||||
|
import {
|
||||||
|
ICredentialType,
|
||||||
|
NodePropertyTypes,
|
||||||
|
} from 'n8n-workflow';
|
||||||
|
|
||||||
|
export class TodoistOAuth2Api implements ICredentialType {
|
||||||
|
name = 'todoistOAuth2Api';
|
||||||
|
extends = [
|
||||||
|
'oAuth2Api',
|
||||||
|
];
|
||||||
|
displayName = 'Todoist OAuth2 API';
|
||||||
|
properties = [
|
||||||
|
{
|
||||||
|
displayName: 'Authorization URL',
|
||||||
|
name: 'authUrl',
|
||||||
|
type: 'hidden' as NodePropertyTypes,
|
||||||
|
default: 'https://todoist.com/oauth/authorize',
|
||||||
|
required: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
displayName: 'Access Token URL',
|
||||||
|
name: 'accessTokenUrl',
|
||||||
|
type: 'hidden' as NodePropertyTypes,
|
||||||
|
default: 'https://todoist.com/oauth/access_token',
|
||||||
|
required: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
displayName: 'Scope',
|
||||||
|
name: 'scope',
|
||||||
|
type: 'hidden' as NodePropertyTypes,
|
||||||
|
default: 'data:read_write,data:delete',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
displayName: 'Auth URI Query Parameters',
|
||||||
|
name: 'authQueryParameters',
|
||||||
|
type: 'hidden' as NodePropertyTypes,
|
||||||
|
default: '',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
displayName: 'Authentication',
|
||||||
|
name: 'authentication',
|
||||||
|
type: 'hidden' as NodePropertyTypes,
|
||||||
|
default: 'body',
|
||||||
|
},
|
||||||
|
];
|
||||||
|
}
|
|
@ -1,66 +1,37 @@
|
||||||
import { OptionsWithUri } from 'request';
|
import {
|
||||||
|
OptionsWithUri,
|
||||||
|
} from 'request';
|
||||||
|
|
||||||
import {
|
import {
|
||||||
IExecuteFunctions,
|
IExecuteFunctions,
|
||||||
IHookFunctions,
|
IHookFunctions,
|
||||||
ILoadOptionsFunctions,
|
ILoadOptionsFunctions,
|
||||||
IExecuteSingleFunctions
|
|
||||||
} from 'n8n-core';
|
} from 'n8n-core';
|
||||||
|
|
||||||
import * as _ from 'lodash';
|
import {
|
||||||
|
IDataObject,
|
||||||
export const filterAndExecuteForEachTask = async function(
|
} from 'n8n-workflow';
|
||||||
this: IExecuteSingleFunctions,
|
|
||||||
taskCallback: (t: any) => any
|
|
||||||
) {
|
|
||||||
const expression = this.getNodeParameter('expression') as string;
|
|
||||||
const projectId = this.getNodeParameter('project') as number;
|
|
||||||
// Enable regular expressions
|
|
||||||
const reg = new RegExp(expression);
|
|
||||||
const tasks = await todoistApiRequest.call(this, '/tasks', 'GET');
|
|
||||||
const filteredTasks = tasks.filter(
|
|
||||||
// Make sure that project will match no matter what the type is. If project was not selected match all projects
|
|
||||||
(el: any) => (!projectId || el.project_id) && el.content.match(reg)
|
|
||||||
);
|
|
||||||
return {
|
|
||||||
affectedTasks: (
|
|
||||||
await Promise.all(filteredTasks.map((t: any) => taskCallback(t)))
|
|
||||||
)
|
|
||||||
// This makes it more clear and informative. We pass the ID as a convention and content to give the user confirmation that his/her expression works as expected
|
|
||||||
.map(
|
|
||||||
(el, i) =>
|
|
||||||
el || { id: filteredTasks[i].id, content: filteredTasks[i].content }
|
|
||||||
)
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
export async function todoistApiRequest(
|
export async function todoistApiRequest(
|
||||||
this:
|
this:
|
||||||
| IHookFunctions
|
| IHookFunctions
|
||||||
| IExecuteFunctions
|
| IExecuteFunctions
|
||||||
| IExecuteSingleFunctions
|
|
||||||
| ILoadOptionsFunctions,
|
| ILoadOptionsFunctions,
|
||||||
resource: string,
|
|
||||||
method: string,
|
method: string,
|
||||||
|
resource: string,
|
||||||
body: any = {},
|
body: any = {},
|
||||||
headers?: object
|
qs: IDataObject = {},
|
||||||
): Promise<any> {
|
): Promise<any> { // tslint:disable-line:no-any
|
||||||
// tslint:disable-line:no-any
|
const authentication = this.getNodeParameter('authentication', 0, 'apiKey');
|
||||||
const credentials = this.getCredentials('todoistApi');
|
|
||||||
|
|
||||||
if (credentials === undefined) {
|
|
||||||
throw new Error('No credentials got returned!');
|
|
||||||
}
|
|
||||||
|
|
||||||
const headerWithAuthentication = Object.assign({}, headers, { Authorization: `Bearer ${credentials.apiKey}` });
|
|
||||||
|
|
||||||
const endpoint = 'api.todoist.com/rest/v1';
|
const endpoint = 'api.todoist.com/rest/v1';
|
||||||
|
|
||||||
const options: OptionsWithUri = {
|
const options: OptionsWithUri = {
|
||||||
headers: headerWithAuthentication,
|
headers: {},
|
||||||
method,
|
method,
|
||||||
|
qs,
|
||||||
uri: `https://${endpoint}${resource}`,
|
uri: `https://${endpoint}${resource}`,
|
||||||
json: true
|
json: true,
|
||||||
};
|
};
|
||||||
|
|
||||||
if (Object.keys(body).length !== 0) {
|
if (Object.keys(body).length !== 0) {
|
||||||
|
@ -68,13 +39,25 @@ export async function todoistApiRequest(
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
if (authentication === 'apiKey') {
|
||||||
|
const credentials = this.getCredentials('todoistApi') as IDataObject;
|
||||||
|
|
||||||
|
//@ts-ignore
|
||||||
|
options.headers['Authorization'] = `Bearer ${credentials.apiKey}`;
|
||||||
|
|
||||||
return this.helpers.request!(options);
|
return this.helpers.request!(options);
|
||||||
|
} else {
|
||||||
|
//@ts-ignore
|
||||||
|
return await this.helpers.requestOAuth2.call(this, 'todoistOAuth2Api', options);
|
||||||
|
}
|
||||||
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
const errorMessage = error.response.body.message || error.response.body.Message;
|
const errorMessage = error.response.body;
|
||||||
|
|
||||||
if (errorMessage !== undefined) {
|
if (errorMessage !== undefined) {
|
||||||
|
throw new Error(errorMessage);
|
||||||
|
}
|
||||||
|
|
||||||
throw errorMessage;
|
throw errorMessage;
|
||||||
}
|
}
|
||||||
throw error.response.body;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
import {
|
import {
|
||||||
IExecuteSingleFunctions,
|
IExecuteFunctions,
|
||||||
} from 'n8n-core';
|
} from 'n8n-core';
|
||||||
|
|
||||||
import {
|
import {
|
||||||
IDataObject,
|
IDataObject,
|
||||||
INodeTypeDescription,
|
INodeTypeDescription,
|
||||||
|
@ -9,12 +10,11 @@ import {
|
||||||
ILoadOptionsFunctions,
|
ILoadOptionsFunctions,
|
||||||
INodePropertyOptions,
|
INodePropertyOptions,
|
||||||
} from 'n8n-workflow';
|
} from 'n8n-workflow';
|
||||||
|
|
||||||
import {
|
import {
|
||||||
todoistApiRequest,
|
todoistApiRequest,
|
||||||
filterAndExecuteForEachTask,
|
|
||||||
} from './GenericFunctions';
|
} from './GenericFunctions';
|
||||||
|
|
||||||
|
|
||||||
interface IBodyCreateTask {
|
interface IBodyCreateTask {
|
||||||
content: string;
|
content: string;
|
||||||
project_id?: number;
|
project_id?: number;
|
||||||
|
@ -48,9 +48,44 @@ export class Todoist implements INodeType {
|
||||||
{
|
{
|
||||||
name: 'todoistApi',
|
name: 'todoistApi',
|
||||||
required: true,
|
required: true,
|
||||||
}
|
displayOptions: {
|
||||||
|
show: {
|
||||||
|
authentication: [
|
||||||
|
'apiKey',
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'todoistOAuth2Api',
|
||||||
|
required: true,
|
||||||
|
displayOptions: {
|
||||||
|
show: {
|
||||||
|
authentication: [
|
||||||
|
'oAuth2',
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
],
|
],
|
||||||
properties: [
|
properties: [
|
||||||
|
{
|
||||||
|
displayName: 'Authentication',
|
||||||
|
name: 'authentication',
|
||||||
|
type: 'options',
|
||||||
|
options: [
|
||||||
|
{
|
||||||
|
name: 'API Key',
|
||||||
|
value: 'apiKey',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'OAuth2',
|
||||||
|
value: 'oAuth2',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
default: 'apiKey',
|
||||||
|
description: 'The resource to operate on.',
|
||||||
|
},
|
||||||
{
|
{
|
||||||
displayName: 'Resource',
|
displayName: 'Resource',
|
||||||
name: 'resource',
|
name: 'resource',
|
||||||
|
@ -85,24 +120,29 @@ export class Todoist implements INodeType {
|
||||||
description: 'Create a new task',
|
description: 'Create a new task',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: 'Close by ID',
|
name: 'Close',
|
||||||
value: 'close_id',
|
value: 'close',
|
||||||
description: 'Close a task by passing an ID',
|
description: 'Close a task',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: 'Close matching',
|
name: 'Delete',
|
||||||
value: 'close_match',
|
value: 'delete',
|
||||||
description: 'Close a task by passing a regular expression',
|
description: 'Delete a task',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: 'Delete by ID',
|
name: 'Get',
|
||||||
value: 'delete_id',
|
value: 'get',
|
||||||
description: 'Delete a task by passing an ID',
|
description: 'Get a task',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: 'Delete matching',
|
name: 'Get All',
|
||||||
value: 'delete_match',
|
value: 'getAll',
|
||||||
description: 'Delete a task by passing a regular expression',
|
description: 'Get all tasks',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'Reopen',
|
||||||
|
value: 'reopen',
|
||||||
|
description: 'Reopen a task',
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
default: 'create',
|
default: 'create',
|
||||||
|
@ -122,9 +162,7 @@ export class Todoist implements INodeType {
|
||||||
],
|
],
|
||||||
operation: [
|
operation: [
|
||||||
'create',
|
'create',
|
||||||
'close_match',
|
],
|
||||||
'delete_match',
|
|
||||||
]
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
default: '',
|
default: '',
|
||||||
|
@ -144,7 +182,7 @@ export class Todoist implements INodeType {
|
||||||
],
|
],
|
||||||
operation: [
|
operation: [
|
||||||
'create',
|
'create',
|
||||||
]
|
],
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
default: [],
|
default: [],
|
||||||
|
@ -165,7 +203,7 @@ export class Todoist implements INodeType {
|
||||||
],
|
],
|
||||||
operation: [
|
operation: [
|
||||||
'create',
|
'create',
|
||||||
]
|
],
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
default: '',
|
default: '',
|
||||||
|
@ -173,32 +211,27 @@ export class Todoist implements INodeType {
|
||||||
description: 'Task content',
|
description: 'Task content',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
displayName: 'ID',
|
displayName: 'Task ID',
|
||||||
name: 'id',
|
name: 'taskId',
|
||||||
type: 'string',
|
type: 'string',
|
||||||
default: '',
|
default: '',
|
||||||
required: true,
|
required: true,
|
||||||
typeOptions: { rows: 1 },
|
|
||||||
displayOptions: {
|
|
||||||
show: { resource: ['task'], operation: ['close_id', 'delete_id'] }
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
displayName: 'Expression to match',
|
|
||||||
name: 'expression',
|
|
||||||
type: 'string',
|
|
||||||
default: '',
|
|
||||||
required: true,
|
|
||||||
typeOptions: { rows: 1 },
|
|
||||||
displayOptions: {
|
displayOptions: {
|
||||||
show: {
|
show: {
|
||||||
resource: ['task'],
|
resource: [
|
||||||
operation: ['close_match', 'delete_match']
|
'task',
|
||||||
}
|
],
|
||||||
}
|
operation: [
|
||||||
|
'delete',
|
||||||
|
'close',
|
||||||
|
'get',
|
||||||
|
'reopen',
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
displayName: 'Options',
|
displayName: 'Additional Fields',
|
||||||
name: 'options',
|
name: 'options',
|
||||||
type: 'collection',
|
type: 'collection',
|
||||||
placeholder: 'Add Option',
|
placeholder: 'Add Option',
|
||||||
|
@ -210,22 +243,10 @@ export class Todoist implements INodeType {
|
||||||
],
|
],
|
||||||
operation: [
|
operation: [
|
||||||
'create',
|
'create',
|
||||||
]
|
],
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
options: [
|
options: [
|
||||||
{
|
|
||||||
displayName: 'Priority',
|
|
||||||
name: 'priority',
|
|
||||||
type: 'number',
|
|
||||||
typeOptions: {
|
|
||||||
numberStepSize: 1,
|
|
||||||
maxValue: 4,
|
|
||||||
minValue: 1,
|
|
||||||
},
|
|
||||||
default: 1,
|
|
||||||
description: 'Task priority from 1 (normal) to 4 (urgent).',
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
displayName: 'Due Date Time',
|
displayName: 'Due Date Time',
|
||||||
name: 'dueDateTime',
|
name: 'dueDateTime',
|
||||||
|
@ -240,24 +261,131 @@ export class Todoist implements INodeType {
|
||||||
default: '',
|
default: '',
|
||||||
description: 'Human defined task due date (ex.: “next Monday”, “Tomorrow”). Value is set using local (not UTC) time.',
|
description: 'Human defined task due date (ex.: “next Monday”, “Tomorrow”). Value is set using local (not UTC) time.',
|
||||||
},
|
},
|
||||||
]
|
{
|
||||||
}
|
displayName: 'Priority',
|
||||||
]
|
name: 'priority',
|
||||||
|
type: 'number',
|
||||||
|
typeOptions: {
|
||||||
|
numberStepSize: 1,
|
||||||
|
maxValue: 4,
|
||||||
|
minValue: 1,
|
||||||
|
},
|
||||||
|
default: 1,
|
||||||
|
description: 'Task priority from 1 (normal) to 4 (urgent).',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
displayName: 'Return All',
|
||||||
|
name: 'returnAll',
|
||||||
|
type: 'boolean',
|
||||||
|
displayOptions: {
|
||||||
|
show: {
|
||||||
|
operation: [
|
||||||
|
'getAll',
|
||||||
|
],
|
||||||
|
resource: [
|
||||||
|
'task',
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
default: false,
|
||||||
|
description: 'If all results should be returned or only up to a given limit.',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
displayName: 'Limit',
|
||||||
|
name: 'limit',
|
||||||
|
type: 'number',
|
||||||
|
displayOptions: {
|
||||||
|
show: {
|
||||||
|
operation: [
|
||||||
|
'getAll',
|
||||||
|
],
|
||||||
|
resource: [
|
||||||
|
'task',
|
||||||
|
],
|
||||||
|
returnAll: [
|
||||||
|
false,
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
typeOptions: {
|
||||||
|
minValue: 1,
|
||||||
|
maxValue: 500,
|
||||||
|
},
|
||||||
|
default: 100,
|
||||||
|
description: 'How many results to return.',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
displayName: 'Filters',
|
||||||
|
name: 'filters',
|
||||||
|
type: 'collection',
|
||||||
|
placeholder: 'Add Option',
|
||||||
|
default: {},
|
||||||
|
displayOptions: {
|
||||||
|
show: {
|
||||||
|
resource: [
|
||||||
|
'task',
|
||||||
|
],
|
||||||
|
operation: [
|
||||||
|
'getAll',
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
options: [
|
||||||
|
{
|
||||||
|
displayName: 'Filter',
|
||||||
|
name: 'filter',
|
||||||
|
type: 'string',
|
||||||
|
default: '',
|
||||||
|
description: 'Filter by any <a href="https://get.todoist.help/hc/en-us/articles/205248842">supported filter.</a>',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
displayName: 'IDs',
|
||||||
|
name: 'ids',
|
||||||
|
type: 'string',
|
||||||
|
default: '',
|
||||||
|
description: 'A list of the task IDs to retrieve, this should be a comma separated list.',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
displayName: 'Label ID',
|
||||||
|
name: 'labelId',
|
||||||
|
type: 'options',
|
||||||
|
typeOptions: {
|
||||||
|
loadOptionsMethod: 'getLabels',
|
||||||
|
},
|
||||||
|
default: {},
|
||||||
|
description: 'Filter tasks by label.',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
displayName: 'Lang',
|
||||||
|
name: 'lang',
|
||||||
|
type: 'string',
|
||||||
|
default: '',
|
||||||
|
description: 'IETF language tag defining what language filter is written in, if differs from default English',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
displayName: 'Project ID',
|
||||||
|
name: 'projectId',
|
||||||
|
type: 'options',
|
||||||
|
typeOptions: {
|
||||||
|
loadOptionsMethod: 'getProjects',
|
||||||
|
},
|
||||||
|
default: '',
|
||||||
|
description: 'Filter tasks by project id.',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
],
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
methods = {
|
methods = {
|
||||||
loadOptions: {
|
loadOptions: {
|
||||||
// Get all the available projects to display them to user so that he can
|
// Get all the available projects to display them to user so that he can
|
||||||
// select them easily
|
// select them easily
|
||||||
async getProjects(this: ILoadOptionsFunctions): Promise<INodePropertyOptions[]> {
|
async getProjects(this: ILoadOptionsFunctions): Promise<INodePropertyOptions[]> {
|
||||||
const returnData: INodePropertyOptions[] = [];
|
const returnData: INodePropertyOptions[] = [];
|
||||||
let projects;
|
const projects = await todoistApiRequest.call(this, 'GET', '/projects');
|
||||||
try {
|
|
||||||
projects = await todoistApiRequest.call(this, '/projects', 'GET');
|
|
||||||
} catch (err) {
|
|
||||||
throw new Error(`Todoist Error: ${err}`);
|
|
||||||
}
|
|
||||||
for (const project of projects) {
|
for (const project of projects) {
|
||||||
const projectName = project.name;
|
const projectName = project.name;
|
||||||
const projectId = project.id;
|
const projectId = project.id;
|
||||||
|
@ -275,12 +403,8 @@ export class Todoist implements INodeType {
|
||||||
// select them easily
|
// select them easily
|
||||||
async getLabels(this: ILoadOptionsFunctions): Promise<INodePropertyOptions[]> {
|
async getLabels(this: ILoadOptionsFunctions): Promise<INodePropertyOptions[]> {
|
||||||
const returnData: INodePropertyOptions[] = [];
|
const returnData: INodePropertyOptions[] = [];
|
||||||
let labels;
|
const labels = await todoistApiRequest.call(this, 'GET', '/labels');
|
||||||
try {
|
|
||||||
labels = await todoistApiRequest.call(this, '/labels', 'GET');
|
|
||||||
} catch (err) {
|
|
||||||
throw new Error(`Todoist Error: ${err}`);
|
|
||||||
}
|
|
||||||
for (const label of labels) {
|
for (const label of labels) {
|
||||||
const labelName = label.name;
|
const labelName = label.name;
|
||||||
const labelId = label.id;
|
const labelId = label.id;
|
||||||
|
@ -296,29 +420,23 @@ export class Todoist implements INodeType {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
async executeSingle(this: IExecuteSingleFunctions): Promise<INodeExecutionData> {
|
async execute(this: IExecuteFunctions): Promise<INodeExecutionData[][]> {
|
||||||
const resource = this.getNodeParameter('resource') as string;
|
const items = this.getInputData();
|
||||||
const operation = this.getNodeParameter('operation') as string;
|
const returnData: IDataObject[] = [];
|
||||||
try {
|
const length = items.length as unknown as number;
|
||||||
return {
|
const qs: IDataObject = {};
|
||||||
json: { result: await OPERATIONS[resource]?.[operation]?.bind(this)() }
|
let responseData;
|
||||||
};
|
for (let i = 0; i < length; i++) {
|
||||||
} catch (err) {
|
const resource = this.getNodeParameter('resource', 0) as string;
|
||||||
return { json: { error: `Todoist Error: ${err.message}` } };
|
const operation = this.getNodeParameter('operation', 0) as string;
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const OPERATIONS: {
|
if (resource === 'task') {
|
||||||
[key: string]: { [key: string]: (this: IExecuteSingleFunctions) => any };
|
if (operation === 'create') {
|
||||||
} = {
|
|
||||||
task: {
|
|
||||||
create(this: IExecuteSingleFunctions) {
|
|
||||||
//https://developer.todoist.com/rest/v1/#create-a-new-task
|
//https://developer.todoist.com/rest/v1/#create-a-new-task
|
||||||
const content = this.getNodeParameter('content') as string;
|
const content = this.getNodeParameter('content', i) as string;
|
||||||
const projectId = this.getNodeParameter('project') as number;
|
const projectId = this.getNodeParameter('project', i) as number;
|
||||||
const labels = this.getNodeParameter('labels') as number[];
|
const labels = this.getNodeParameter('labels', i) as number[];
|
||||||
const options = this.getNodeParameter('options') as IDataObject;
|
const options = this.getNodeParameter('options', i) as IDataObject;
|
||||||
|
|
||||||
const body: IBodyCreateTask = {
|
const body: IBodyCreateTask = {
|
||||||
content,
|
content,
|
||||||
|
@ -338,25 +456,75 @@ const OPERATIONS: {
|
||||||
body.label_ids = labels;
|
body.label_ids = labels;
|
||||||
}
|
}
|
||||||
|
|
||||||
return todoistApiRequest.call(this, '/tasks', 'POST', body);
|
responseData = await todoistApiRequest.call(this, 'POST', '/tasks', body);
|
||||||
},
|
}
|
||||||
close_id(this: IExecuteSingleFunctions) {
|
if (operation === 'close') {
|
||||||
const id = this.getNodeParameter('id') as string;
|
//https://developer.todoist.com/rest/v1/#close-a-task
|
||||||
return todoistApiRequest.call(this, `/tasks/${id}/close`, 'POST');
|
const id = this.getNodeParameter('taskId', i) as string;
|
||||||
},
|
|
||||||
delete_id(this: IExecuteSingleFunctions) {
|
responseData = await todoistApiRequest.call(this, 'POST', `/tasks/${id}/close`);
|
||||||
const id = this.getNodeParameter('id') as string;
|
|
||||||
return todoistApiRequest.call(this, `/tasks/${id}`, 'DELETE');
|
responseData = { success: true };
|
||||||
},
|
|
||||||
close_match(this) {
|
}
|
||||||
return filterAndExecuteForEachTask.call(this, t =>
|
if (operation === 'delete') {
|
||||||
todoistApiRequest.call(this, `/tasks/${t.id}/close`, 'POST')
|
//https://developer.todoist.com/rest/v1/#delete-a-task
|
||||||
);
|
const id = this.getNodeParameter('taskId', i) as string;
|
||||||
},
|
|
||||||
delete_match(this) {
|
responseData = await todoistApiRequest.call(this, 'DELETE', `/tasks/${id}`);
|
||||||
return filterAndExecuteForEachTask.call(this, t =>
|
|
||||||
todoistApiRequest.call(this, `/tasks/${t.id}`, 'DELETE')
|
responseData = { success: true };
|
||||||
);
|
|
||||||
|
}
|
||||||
|
if (operation === 'get') {
|
||||||
|
//https://developer.todoist.com/rest/v1/#get-an-active-task
|
||||||
|
const id = this.getNodeParameter('taskId', i) as string;
|
||||||
|
|
||||||
|
responseData = await todoistApiRequest.call(this, 'GET', `/tasks/${id}`);
|
||||||
|
}
|
||||||
|
if (operation === 'getAll') {
|
||||||
|
//https://developer.todoist.com/rest/v1/#get-active-tasks
|
||||||
|
const returnAll = this.getNodeParameter('returnAll', i) as boolean;
|
||||||
|
const filters = this.getNodeParameter('filters', i) as IDataObject;
|
||||||
|
if (filters.projectId) {
|
||||||
|
qs.project_id = filters.projectId as string;
|
||||||
|
}
|
||||||
|
if (filters.labelId) {
|
||||||
|
qs.label_id = filters.labelId as string;
|
||||||
|
}
|
||||||
|
if (filters.filter) {
|
||||||
|
qs.filter = filters.filter as string;
|
||||||
|
}
|
||||||
|
if (filters.lang) {
|
||||||
|
qs.lang = filters.lang as string;
|
||||||
|
}
|
||||||
|
if (filters.ids) {
|
||||||
|
qs.ids = filters.ids as string;
|
||||||
|
}
|
||||||
|
|
||||||
|
responseData = await todoistApiRequest.call(this, 'GET', '/tasks', {}, qs);
|
||||||
|
|
||||||
|
if (!returnAll) {
|
||||||
|
const limit = this.getNodeParameter('limit', i) as number;
|
||||||
|
responseData = responseData.splice(0, limit);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
if (operation === 'reopen') {
|
||||||
|
//https://developer.todoist.com/rest/v1/#get-an-active-task
|
||||||
|
const id = this.getNodeParameter('taskId', i) as string;
|
||||||
|
|
||||||
|
responseData = await todoistApiRequest.call(this, 'POST', `/tasks/${id}/reopen`);
|
||||||
|
|
||||||
|
responseData = { success: true };
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (Array.isArray(responseData)) {
|
||||||
|
returnData.push.apply(returnData, responseData as IDataObject[]);
|
||||||
|
} else {
|
||||||
|
returnData.push(responseData as IDataObject);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return [this.helpers.returnJsonArray(returnData)];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Binary file not shown.
Before Width: | Height: | Size: 4 KiB After Width: | Height: | Size: 5.5 KiB |
|
@ -151,6 +151,7 @@
|
||||||
"dist/credentials/SurveyMonkeyOAuth2Api.credentials.js",
|
"dist/credentials/SurveyMonkeyOAuth2Api.credentials.js",
|
||||||
"dist/credentials/TelegramApi.credentials.js",
|
"dist/credentials/TelegramApi.credentials.js",
|
||||||
"dist/credentials/TodoistApi.credentials.js",
|
"dist/credentials/TodoistApi.credentials.js",
|
||||||
|
"dist/credentials/TodoistOAuth2Api.credentials.js",
|
||||||
"dist/credentials/TravisCiApi.credentials.js",
|
"dist/credentials/TravisCiApi.credentials.js",
|
||||||
"dist/credentials/TrelloApi.credentials.js",
|
"dist/credentials/TrelloApi.credentials.js",
|
||||||
"dist/credentials/TwilioApi.credentials.js",
|
"dist/credentials/TwilioApi.credentials.js",
|
||||||
|
|
Loading…
Reference in a new issue