diff --git a/packages/nodes-base/nodes/Todoist/Todoist.node.ts b/packages/nodes-base/nodes/Todoist/Todoist.node.ts index 27566c46d..0de9ed896 100644 --- a/packages/nodes-base/nodes/Todoist/Todoist.node.ts +++ b/packages/nodes-base/nodes/Todoist/Todoist.node.ts @@ -11,7 +11,7 @@ export class Todoist extends VersionedNodeType { name: 'todoist', icon: 'file:todoist.svg', group: ['output'], - defaultVersion: 2, + defaultVersion: 2.1, subtitle: '={{$parameter["operation"] + ": " + $parameter["resource"]}}', description: 'Consume Todoist API', }; @@ -19,6 +19,7 @@ export class Todoist extends VersionedNodeType { const nodeVersions: IVersionedNodeType['nodeVersions'] = { 1: new TodoistV1(baseDescription), 2: new TodoistV2(baseDescription), + 2.1: new TodoistV2(baseDescription), }; super(nodeVersions, baseDescription); diff --git a/packages/nodes-base/nodes/Todoist/v2/OperationHandler.ts b/packages/nodes-base/nodes/Todoist/v2/OperationHandler.ts index 19e9c661a..a1b706cac 100644 --- a/packages/nodes-base/nodes/Todoist/v2/OperationHandler.ts +++ b/packages/nodes-base/nodes/Todoist/v2/OperationHandler.ts @@ -34,6 +34,7 @@ export interface Command { uuid: string; temp_id?: string; args: { + parent_id?: string; id?: number; section_id?: number; project_id?: number | string; @@ -251,7 +252,10 @@ export class MoveHandler implements OperationHandler { async handleOperation(ctx: Context, itemIndex: number): Promise { //https://api.todoist.com/sync/v9/sync const taskId = ctx.getNodeParameter('taskId', itemIndex) as number; - const section = ctx.getNodeParameter('section', itemIndex) as number; + const projectId = ctx.getNodeParameter('project', itemIndex, undefined, { + extractValue: true, + }) as number; + const nodeVersion = ctx.getNode().typeVersion; const body: SyncRequest = { commands: [ @@ -260,14 +264,28 @@ export class MoveHandler implements OperationHandler { uuid: uuid(), args: { id: taskId, - section_id: section, + // Set section_id only if node version is below 2.1 + ...(nodeVersion < 2.1 + ? { section_id: ctx.getNodeParameter('section', itemIndex) as number } + : {}), }, }, ], }; - await todoistSyncRequest.call(ctx, body); + if (nodeVersion >= 2.1) { + const options = ctx.getNodeParameter('options', itemIndex, {}) as IDataObject; + // Only one of parent_id, section_id, or project_id must be set to move the task + if (options.parent) { + body.commands[0].args.parent_id = options.parent as string; + } else if (options.section) { + body.commands[0].args.section_id = options.section as number; + } else { + body.commands[0].args.project_id = projectId; + } + } + await todoistSyncRequest.call(ctx, body); return { success: true }; } } diff --git a/packages/nodes-base/nodes/Todoist/v2/TodoistV2.node.ts b/packages/nodes-base/nodes/Todoist/v2/TodoistV2.node.ts index 24608ab1e..bcae9206e 100644 --- a/packages/nodes-base/nodes/Todoist/v2/TodoistV2.node.ts +++ b/packages/nodes-base/nodes/Todoist/v2/TodoistV2.node.ts @@ -36,7 +36,7 @@ const versionDescription: INodeTypeDescription = { name: 'todoist', icon: 'file:todoist.svg', group: ['output'], - version: 2, + version: [2, 2.1], subtitle: '={{$parameter["operation"] + ": " + $parameter["resource"]}}', description: 'Consume Todoist API', defaults: { @@ -207,7 +207,7 @@ const versionDescription: INodeTypeDescription = { operation: ['create', 'move', 'sync'], }, }, - description: 'The project you want to operate on. Choose from the list, or specify an ID.', + description: 'The destination project. Choose from the list, or specify an ID.', }, { displayName: 'Section Name or ID', @@ -222,11 +222,54 @@ const versionDescription: INodeTypeDescription = { resource: ['task'], operation: ['move'], }, + hide: { + '@version': [{ _cnd: { gte: 2.1 } }], + }, }, default: '', description: 'Section to which you want move the task. Choose from the list, or specify an ID using an expression.', }, + { + displayName: 'Additional Fields', + name: 'options', + type: 'collection', + placeholder: 'Add option', + default: {}, + displayOptions: { + show: { + resource: ['task'], + operation: ['move'], + '@version': [{ _cnd: { gte: 2.1 } }], + }, + }, + options: [ + { + displayName: 'Section Name or ID', + name: 'section', + type: 'options', + typeOptions: { + loadOptionsMethod: 'getSections', + loadOptionsDependsOn: ['project', 'options.parent'], + }, + default: '', + description: + 'The destination section. The task becomes the last root task of the section. Choose from the list, or specify an ID using an expression.', + }, + { + displayName: 'Parent Name or ID', + name: 'parent', + type: 'options', + typeOptions: { + loadOptionsMethod: 'getItems', + loadOptionsDependsOn: ['project', 'options.section'], + }, + default: '', + description: + 'The destination parent task. The task becomes the last child task of the parent task. Choose from the list, or specify an ID using an expression.', + }, + ], + }, { displayName: 'Label Names or IDs', name: 'labels',