Minor improvements to Todoist-Node

This commit is contained in:
Jan Oberhauser
2020-08-26 09:28:39 +02:00
parent c3277df25b
commit d768764a70
3 changed files with 32 additions and 30 deletions

View File

@@ -2,7 +2,7 @@
This list shows all the versions which include breaking changes and how to upgrade. This list shows all the versions which include breaking changes and how to upgrade.
## 0.80.0 ## 0.79.0
### What changed? ### What changed?

View File

@@ -19,7 +19,7 @@ export async function todoistApiRequest(
| ILoadOptionsFunctions, | ILoadOptionsFunctions,
method: string, method: string,
resource: string, resource: string,
body: any = {}, body: any = {}, // tslint:disable-line:no-any
qs: IDataObject = {}, qs: IDataObject = {},
): Promise<any> { // tslint:disable-line:no-any ): Promise<any> { // tslint:disable-line:no-any
const authentication = this.getNodeParameter('authentication', 0, 'apiKey'); const authentication = this.getNodeParameter('authentication', 0, 'apiKey');

View File

@@ -426,52 +426,54 @@ export class Todoist implements INodeType {
const length = items.length as unknown as number; const length = items.length as unknown as number;
const qs: IDataObject = {}; const qs: IDataObject = {};
let responseData; let responseData;
const resource = this.getNodeParameter('resource', 0) as string;
const operation = this.getNodeParameter('operation', 0) as string;
for (let i = 0; i < length; i++) { for (let i = 0; i < length; i++) {
const resource = this.getNodeParameter('resource', 0) as string;
const operation = this.getNodeParameter('operation', 0) as string;
if (resource === 'task') { if (resource === 'task') {
if (operation === 'create') { if (operation === 'create') {
//https://developer.todoist.com/rest/v1/#create-a-new-task //https://developer.todoist.com/rest/v1/#create-a-new-task
const content = this.getNodeParameter('content', i) as string; const content = this.getNodeParameter('content', i) as string;
const projectId = this.getNodeParameter('project', i) as number; const projectId = this.getNodeParameter('project', i) as number;
const labels = this.getNodeParameter('labels', i) as number[]; const labels = this.getNodeParameter('labels', i) as number[];
const options = this.getNodeParameter('options', i) as IDataObject; const options = this.getNodeParameter('options', i) as IDataObject;
const body: IBodyCreateTask = { const body: IBodyCreateTask = {
content, content,
project_id: projectId, project_id: projectId,
priority: (options.priority!) ? parseInt(options.priority as string, 10) : 1, priority: (options.priority!) ? parseInt(options.priority as string, 10) : 1,
}; };
if (options.dueDateTime) { if (options.dueDateTime) {
body.due_datetime = options.dueDateTime as string; body.due_datetime = options.dueDateTime as string;
} }
if (options.dueString) { if (options.dueString) {
body.due_string = options.dueString as string; body.due_string = options.dueString as string;
} }
if (labels !== undefined && labels.length !== 0) { if (labels !== undefined && labels.length !== 0) {
body.label_ids = labels; body.label_ids = labels;
} }
responseData = await todoistApiRequest.call(this, 'POST', '/tasks', body); responseData = await todoistApiRequest.call(this, 'POST', '/tasks', body);
} }
if (operation === 'close') { if (operation === 'close') {
//https://developer.todoist.com/rest/v1/#close-a-task //https://developer.todoist.com/rest/v1/#close-a-task
const id = this.getNodeParameter('taskId', i) as string; const id = this.getNodeParameter('taskId', i) as string;
responseData = await todoistApiRequest.call(this, 'POST', `/tasks/${id}/close`); responseData = await todoistApiRequest.call(this, 'POST', `/tasks/${id}/close`);
responseData = { success: true }; responseData = { success: true };
} }
if (operation === 'delete') { if (operation === 'delete') {
//https://developer.todoist.com/rest/v1/#delete-a-task //https://developer.todoist.com/rest/v1/#delete-a-task
const id = this.getNodeParameter('taskId', i) as string; const id = this.getNodeParameter('taskId', i) as string;
responseData = await todoistApiRequest.call(this, 'DELETE', `/tasks/${id}`); responseData = await todoistApiRequest.call(this, 'DELETE', `/tasks/${id}`);
responseData = { success: true }; responseData = { success: true };
@@ -480,7 +482,7 @@ export class Todoist implements INodeType {
//https://developer.todoist.com/rest/v1/#get-an-active-task //https://developer.todoist.com/rest/v1/#get-an-active-task
const id = this.getNodeParameter('taskId', i) as string; const id = this.getNodeParameter('taskId', i) as string;
responseData = await todoistApiRequest.call(this, 'GET', `/tasks/${id}`); responseData = await todoistApiRequest.call(this, 'GET', `/tasks/${id}`);
} }
if (operation === 'getAll') { if (operation === 'getAll') {
//https://developer.todoist.com/rest/v1/#get-active-tasks //https://developer.todoist.com/rest/v1/#get-active-tasks
@@ -513,7 +515,7 @@ export class Todoist implements INodeType {
//https://developer.todoist.com/rest/v1/#get-an-active-task //https://developer.todoist.com/rest/v1/#get-an-active-task
const id = this.getNodeParameter('taskId', i) as string; const id = this.getNodeParameter('taskId', i) as string;
responseData = await todoistApiRequest.call(this, 'POST', `/tasks/${id}/reopen`); responseData = await todoistApiRequest.call(this, 'POST', `/tasks/${id}/reopen`);
responseData = { success: true }; responseData = { success: true };
} }