diff --git a/packages/nodes-base/nodes/Todoist/GenericFunctions.ts b/packages/nodes-base/nodes/Todoist/GenericFunctions.ts index 97665c3c4c..bd09118dae 100644 --- a/packages/nodes-base/nodes/Todoist/GenericFunctions.ts +++ b/packages/nodes-base/nodes/Todoist/GenericFunctions.ts @@ -44,7 +44,6 @@ export async function todoistApiRequest( //@ts-ignore options.headers['Authorization'] = `Bearer ${credentials.apiKey}`; - return this.helpers.request!(options); } else { //@ts-ignore diff --git a/packages/nodes-base/nodes/Todoist/Todoist.node.ts b/packages/nodes-base/nodes/Todoist/Todoist.node.ts index 4aeca39d81..a4ebc6fe2d 100644 --- a/packages/nodes-base/nodes/Todoist/Todoist.node.ts +++ b/packages/nodes-base/nodes/Todoist/Todoist.node.ts @@ -16,7 +16,7 @@ import { } from './GenericFunctions'; interface IBodyCreateTask { - content: string; + content?: string; description?: string; project_id?: number; section_id?: number; @@ -146,6 +146,11 @@ export class Todoist implements INodeType { value: 'reopen', description: 'Reopen a task', }, + { + name: 'Update', + value: 'update', + description: 'Update a task', + }, ], default: 'create', description: 'The operation to perform.', @@ -228,6 +233,7 @@ export class Todoist implements INodeType { 'close', 'get', 'reopen', + 'update', ], }, }, @@ -398,6 +404,76 @@ export class Todoist implements INodeType { }, ], }, + { + displayName: 'Update Fields', + name: 'updateFields', + type: 'collection', + placeholder: 'Add Field', + default: {}, + displayOptions: { + show: { + resource: [ + 'task', + ], + operation: [ + 'update', + ], + }, + }, + options: [ + { + displayName: 'Content', + name: 'content', + type: 'string', + default: '', + description: 'Task content', + }, + { + displayName: 'Description', + name: 'description', + type: 'string', + default: '', + description: 'A description for the task.', + }, + { + displayName: 'Due Date Time', + name: 'dueDateTime', + type: 'dateTime', + default: '', + description: 'Specific date and time in RFC3339 format in UTC.', + }, + { + displayName: 'Due String', + name: 'dueString', + type: 'string', + default: '', + description: 'Human defined task due date (ex.: “next Monday”, “Tomorrow”). Value is set using local (not UTC) time.', + }, + { + displayName: 'Labels', + name: 'labels', + type: 'multiOptions', + typeOptions: { + loadOptionsMethod: 'getLabels', + }, + default: [], + required: false, + description: 'Labels', + }, + { + displayName: 'Priority', + name: 'priority', + type: 'number', + typeOptions: { + numberStepSize: 1, + maxValue: 4, + minValue: 1, + }, + default: 1, + description: 'Task priority from 1 (normal) to 4 (urgent).', + }, + ], + }, ], }; @@ -485,33 +561,33 @@ export class Todoist implements INodeType { const projectId = this.getNodeParameter('project', i) as number; const labels = this.getNodeParameter('labels', i) as number[]; const options = this.getNodeParameter('options', i) as IDataObject; - + const body: IBodyCreateTask = { content, project_id: projectId, priority: (options.priority!) ? parseInt(options.priority as string, 10) : 1, }; - + if (options.description) { body.description = options.description as string; } - + if (options.dueDateTime) { body.due_datetime = options.dueDateTime as string; } - + if (options.dueString) { body.due_string = options.dueString as string; } - + if (labels !== undefined && labels.length !== 0) { body.label_ids = labels; } - + if (options.section) { body.section_id = options.section as number; } - + responseData = await todoistApiRequest.call(this, 'POST', '/tasks', body); } if (operation === 'close') { @@ -573,6 +649,43 @@ export class Todoist implements INodeType { responseData = { success: true }; } + + if (operation === 'update') { + //https://developer.todoist.com/rest/v1/#update-a-task + const id = this.getNodeParameter('taskId', i) as string; + const updateFields = this.getNodeParameter('updateFields', i) as IDataObject; + + const body: IBodyCreateTask = {}; + + if (updateFields.content) { + body.content = updateFields.content as string; + } + + if (updateFields.priority) { + body.priority = parseInt(updateFields.priority as string, 10); + } + + if (updateFields.description) { + body.description = updateFields.description as string; + } + + if (updateFields.dueDateTime) { + body.due_datetime = updateFields.dueDateTime as string; + } + + if (updateFields.dueString) { + body.due_string = updateFields.dueString as string; + } + + if (updateFields.labels !== undefined && + Array.isArray(updateFields.labels) && + updateFields.labels.length !== 0) { + body.label_ids = updateFields.labels as number[]; + } + + await todoistApiRequest.call(this, 'POST', `/tasks/${id}`, body); + responseData = { success: true }; + } } if (Array.isArray(responseData)) { returnData.push.apply(returnData, responseData as IDataObject[]);