From 63f2865d44d97e782a70efa432e406e49ff039ea Mon Sep 17 00:00:00 2001 From: Thomas Jost Date: Sun, 31 Jan 2021 19:09:24 +0100 Subject: [PATCH] :sparkles: Add support for Todoist sections (#1374) --- .../nodes-base/nodes/Todoist/Todoist.node.ts | 41 +++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/packages/nodes-base/nodes/Todoist/Todoist.node.ts b/packages/nodes-base/nodes/Todoist/Todoist.node.ts index 4190f54cdc..4bb77324b7 100644 --- a/packages/nodes-base/nodes/Todoist/Todoist.node.ts +++ b/packages/nodes-base/nodes/Todoist/Todoist.node.ts @@ -18,6 +18,7 @@ import { interface IBodyCreateTask { content: string; project_id?: number; + section_id?: number; parent?: number; order?: number; label_ids?: number[]; @@ -273,6 +274,19 @@ export class Todoist implements INodeType { default: 1, description: 'Task priority from 1 (normal) to 4 (urgent).', }, + { + displayName: 'Section', + name: 'section', + type: 'options', + typeOptions: { + loadOptionsMethod: 'getSections', + loadOptionsDependsOn: [ + 'project', + ], + }, + default: {}, + description: 'The section you want to operate on.', + }, ], }, { @@ -399,6 +413,29 @@ export class Todoist implements INodeType { return returnData; }, + // Get all the available sections in the selected project, to display them + // to user so that he can select one easily + async getSections(this: ILoadOptionsFunctions): Promise { + const returnData: INodePropertyOptions[] = []; + + const projectId = this.getCurrentNodeParameter('project') as number; + if (projectId) { + const qs: IDataObject = {project_id: projectId}; + const sections = await todoistApiRequest.call(this, 'GET', '/sections', {}, qs); + for (const section of sections) { + const sectionName = section.name; + const sectionId = section.id; + + returnData.push({ + name: sectionName, + value: sectionId, + }); + } + } + + return returnData; + }, + // Get all the available labels to display them to user so that he can // select them easily async getLabels(this: ILoadOptionsFunctions): Promise { @@ -458,6 +495,10 @@ export class Todoist implements INodeType { 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') {