From 9d50fb0c3361eceb3ac98a6f75da2c2aaa5db551 Mon Sep 17 00:00:00 2001 From: Ricardo Espinoza Date: Tue, 5 Nov 2019 18:50:55 -0500 Subject: [PATCH] done --- .../nodes-base/nodes/Todoist/Todoist.node.ts | 68 ++++++++++++++++--- 1 file changed, 59 insertions(+), 9 deletions(-) diff --git a/packages/nodes-base/nodes/Todoist/Todoist.node.ts b/packages/nodes-base/nodes/Todoist/Todoist.node.ts index 5484b987bc..db585c3e99 100644 --- a/packages/nodes-base/nodes/Todoist/Todoist.node.ts +++ b/packages/nodes-base/nodes/Todoist/Todoist.node.ts @@ -14,6 +14,7 @@ import { } from './GenericFunctions'; import moment = require('moment'); +import _ = require('lodash') export class Todoist implements INodeType { @@ -94,6 +95,27 @@ export class Todoist implements INodeType { }, default: [], description: 'The project you want to add the task to.', + }, + { + displayName: 'Labels', + name: 'labels', + type: 'multiOptions', + typeOptions: { + loadOptionsMethod: 'getLabels', + }, + displayOptions: { + show: { + resource: [ + 'task', + ], + operation: [ + 'create' + ] + }, + }, + default: [], + required: false, + description: 'Labels', }, { displayName: 'Content', @@ -115,7 +137,7 @@ export class Todoist implements INodeType { default: [], required: true, description: 'Task content', - }, + }, { displayName: 'Options', name: 'options', @@ -187,12 +209,34 @@ export class Todoist implements INodeType { }); } + return returnData + }, + + // Get all the available labels to display them to user so that he can + // select them easily + async getLabels(this: ILoadOptionsFunctions): Promise { + const returnData: INodePropertyOptions[] = []; + let labels; + try { + labels = await todoistApiRequest.call(this, '/labels', 'GET'); + } catch (err) { + throw new Error(`Todoist Error: ${err}`); + } + for (const label of labels) { + const labelName = label.name; + const labelId = label.id; + + returnData.push({ + name: labelName, + value: labelId, + }); + } + return returnData } - }, + } }; - async executeSingle(this: IExecuteSingleFunctions): Promise { const resource = this.getNodeParameter('resource') as string; @@ -205,9 +249,9 @@ export class Todoist implements INodeType { const content = this.getNodeParameter('content') as string; const projectId = this.getNodeParameter('project') as number; + const labels = this.getNodeParameter('labels') as [number]; const options = this.getNodeParameter('options') as IDataObject; - interface IBodyCreateTask { content: string; project_id?: number; @@ -224,17 +268,23 @@ export class Todoist implements INodeType { const body: IBodyCreateTask = { content, project_id: projectId, - priority: (options.priority!) ? parseInt(options.priority, 10) : 1, - } + priority: (options.priority!) ? parseInt(options.priority as string, 10) : 1, + }; if (options.dueDateTime) { - body.due_datetime = moment(options.dueDateTime).utc().format() + body.due_datetime = moment(options.dueDateTime as string).utc().format(); } if (options.dueString) { - body.due_string = options.dueString + body.due_string = options.dueString as string; } + if (!_.isEmpty(labels)) { + body.label_ids = labels + } + + console.log(labels) + try { response = await todoistApiRequest.call(this, '/tasks', 'POST', body); } catch (err) { @@ -243,7 +293,7 @@ export class Todoist implements INodeType { } return { - json: response, + json: response }; } }