mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-17 18:12:04 +00:00
⚡ Todoist node enhancement (#763)
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import {
|
||||
import {
|
||||
IExecuteSingleFunctions,
|
||||
} from 'n8n-core';
|
||||
import {
|
||||
@@ -11,6 +11,7 @@ import {
|
||||
} from 'n8n-workflow';
|
||||
import {
|
||||
todoistApiRequest,
|
||||
filterAndExecuteForEachTask,
|
||||
} from './GenericFunctions';
|
||||
|
||||
|
||||
@@ -83,6 +84,26 @@ export class Todoist implements INodeType {
|
||||
value: 'create',
|
||||
description: 'Create a new task',
|
||||
},
|
||||
{
|
||||
name: 'Close by ID',
|
||||
value: 'close_id',
|
||||
description: 'Close a task by passing an ID',
|
||||
},
|
||||
{
|
||||
name: 'Close matching',
|
||||
value: 'close_match',
|
||||
description: 'Close a task by passing a regular expression',
|
||||
},
|
||||
{
|
||||
name: 'Delete by ID',
|
||||
value: 'delete_id',
|
||||
description: 'Delete a task by passing an ID',
|
||||
},
|
||||
{
|
||||
name: 'Delete matching',
|
||||
value: 'delete_match',
|
||||
description: 'Delete a task by passing a regular expression',
|
||||
},
|
||||
],
|
||||
default: 'create',
|
||||
description: 'The operation to perform.',
|
||||
@@ -101,11 +122,13 @@ export class Todoist implements INodeType {
|
||||
],
|
||||
operation: [
|
||||
'create',
|
||||
'close_match',
|
||||
'delete_match',
|
||||
]
|
||||
},
|
||||
},
|
||||
default: '',
|
||||
description: 'The project you want to add the task to.',
|
||||
description: 'The project you want to operate on.',
|
||||
},
|
||||
{
|
||||
displayName: 'Labels',
|
||||
@@ -149,6 +172,31 @@ export class Todoist implements INodeType {
|
||||
required: true,
|
||||
description: 'Task content',
|
||||
},
|
||||
{
|
||||
displayName: 'ID',
|
||||
name: 'id',
|
||||
type: 'string',
|
||||
default: '',
|
||||
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: {
|
||||
show: {
|
||||
resource: ['task'],
|
||||
operation: ['close_match', 'delete_match']
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
displayName: 'Options',
|
||||
name: 'options',
|
||||
@@ -249,12 +297,23 @@ export class Todoist implements INodeType {
|
||||
};
|
||||
|
||||
async executeSingle(this: IExecuteSingleFunctions): Promise<INodeExecutionData> {
|
||||
|
||||
const resource = this.getNodeParameter('resource') as string;
|
||||
const opeation = this.getNodeParameter('operation') as string;
|
||||
let response;
|
||||
const operation = this.getNodeParameter('operation') as string;
|
||||
try {
|
||||
return {
|
||||
json: { result: await OPERATIONS[resource]?.[operation]?.bind(this)() }
|
||||
};
|
||||
} catch (err) {
|
||||
return { json: { error: `Todoist Error: ${err.message}` } };
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (resource === 'task' && opeation === 'create') {
|
||||
const OPERATIONS: {
|
||||
[key: string]: { [key: string]: (this: IExecuteSingleFunctions) => any };
|
||||
} = {
|
||||
task: {
|
||||
create(this: IExecuteSingleFunctions) {
|
||||
//https://developer.todoist.com/rest/v1/#create-a-new-task
|
||||
const content = this.getNodeParameter('content') as string;
|
||||
const projectId = this.getNodeParameter('project') as number;
|
||||
@@ -279,15 +338,25 @@ export class Todoist implements INodeType {
|
||||
body.label_ids = labels;
|
||||
}
|
||||
|
||||
try {
|
||||
response = await todoistApiRequest.call(this, '/tasks', 'POST', body);
|
||||
} catch (err) {
|
||||
throw new Error(`Todoist Error: ${err}`);
|
||||
}
|
||||
return todoistApiRequest.call(this, '/tasks', 'POST', body);
|
||||
},
|
||||
close_id(this: IExecuteSingleFunctions) {
|
||||
const id = this.getNodeParameter('id') as string;
|
||||
return todoistApiRequest.call(this, `/tasks/${id}/close`, 'POST');
|
||||
},
|
||||
delete_id(this: IExecuteSingleFunctions) {
|
||||
const id = this.getNodeParameter('id') as string;
|
||||
return todoistApiRequest.call(this, `/tasks/${id}`, 'DELETE');
|
||||
},
|
||||
close_match(this) {
|
||||
return filterAndExecuteForEachTask.call(this, t =>
|
||||
todoistApiRequest.call(this, `/tasks/${t.id}/close`, 'POST')
|
||||
);
|
||||
},
|
||||
delete_match(this) {
|
||||
return filterAndExecuteForEachTask.call(this, t =>
|
||||
todoistApiRequest.call(this, `/tasks/${t.id}`, 'DELETE')
|
||||
);
|
||||
}
|
||||
|
||||
return {
|
||||
json: response
|
||||
};
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user