mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-17 10:02:05 +00:00
⚡ Todoist node enhancement (#763)
This commit is contained in:
@@ -9,7 +9,43 @@ import {
|
||||
|
||||
import * as _ from 'lodash';
|
||||
|
||||
export async function todoistApiRequest(this: IHookFunctions | IExecuteFunctions | IExecuteSingleFunctions | ILoadOptionsFunctions, resource: string, method: string, body: any = {}, headers?: object): Promise<any> { // tslint:disable-line:no-any
|
||||
export const filterAndExecuteForEachTask = async function(
|
||||
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(
|
||||
this:
|
||||
| IHookFunctions
|
||||
| IExecuteFunctions
|
||||
| IExecuteSingleFunctions
|
||||
| ILoadOptionsFunctions,
|
||||
resource: string,
|
||||
method: string,
|
||||
body: any = {},
|
||||
headers?: object
|
||||
): Promise<any> {
|
||||
// tslint:disable-line:no-any
|
||||
const credentials = this.getCredentials('todoistApi');
|
||||
|
||||
if (credentials === undefined) {
|
||||
@@ -32,7 +68,7 @@ export async function todoistApiRequest(this: IHookFunctions | IExecuteFunctions
|
||||
}
|
||||
|
||||
try {
|
||||
return await this.helpers.request!(options);
|
||||
return this.helpers.request!(options);
|
||||
} catch (error) {
|
||||
const errorMessage = error.response.body.message || error.response.body.Message;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user