Fixed some lint and cosmetic issues

This commit is contained in:
Jan Oberhauser 2019-11-07 08:40:12 +01:00
parent 98ef334ab0
commit 47856f236e
2 changed files with 74 additions and 82 deletions

View file

@ -8,7 +8,6 @@ import {
} from 'n8n-core';
import * as _ from 'lodash';
import { IDataObject } from 'n8n-workflow';
export async function todoistApiRequest(this: IHookFunctions | IExecuteFunctions | IExecuteSingleFunctions | ILoadOptionsFunctions, resource: string, method: string, body: any = {}, headers?: object): Promise<any> { // tslint:disable-line:no-any
const credentials = this.getCredentials('todoistApi');
@ -24,20 +23,17 @@ export async function todoistApiRequest(this: IHookFunctions | IExecuteFunctions
const options: OptionsWithUri = {
headers: headerWithAuthentication,
method,
body,
uri: `https://${endpoint}${resource}`,
json: true
};
if (_.isEmpty(options.body)) {
delete options.body
if (Object.keys(body).length !== 0) {
options.body = body;
}
try {
return await this.helpers.request!(options);
} catch (error) {
//console.error(error);
const errorMessage = error.response.body.message || error.response.body.Message;
if (errorMessage !== undefined) {

View file

@ -10,11 +10,22 @@ import {
INodePropertyOptions,
} from 'n8n-workflow';
import {
todoistApiRequest
todoistApiRequest,
} from './GenericFunctions';
import moment = require('moment');
import _ = require('lodash')
interface IBodyCreateTask {
content: string;
project_id?: number;
parent?: number;
order?: number;
label_ids?: number[];
priority?: number;
due_string?: string;
due_datetime?: string;
due_date?: string;
due_lang?: string;
}
export class Todoist implements INodeType {
@ -50,7 +61,7 @@ export class Todoist implements INodeType {
description: 'Task resource.',
},
],
default: '',
default: 'task',
required: true,
description: 'Resource to consume.',
},
@ -89,7 +100,7 @@ export class Todoist implements INodeType {
'task',
],
operation: [
'create'
'create',
]
},
},
@ -109,7 +120,7 @@ export class Todoist implements INodeType {
'task',
],
operation: [
'create'
'create',
]
},
},
@ -130,7 +141,7 @@ export class Todoist implements INodeType {
'task',
],
operation: [
'create'
'create',
]
},
},
@ -150,7 +161,7 @@ export class Todoist implements INodeType {
'task',
],
operation: [
'create'
'create',
]
},
},
@ -162,7 +173,7 @@ export class Todoist implements INodeType {
typeOptions: {
numberStepSize: 1,
maxValue: 4,
minValue: 1
minValue: 1,
},
default: 1,
description: 'Task priority from 1 (normal) to 4 (urgent).',
@ -209,7 +220,7 @@ export class Todoist implements INodeType {
});
}
return returnData
return returnData;
},
// Get all the available labels to display them to user so that he can
@ -232,7 +243,7 @@ export class Todoist implements INodeType {
});
}
return returnData
return returnData;
}
}
};
@ -244,27 +255,12 @@ export class Todoist implements INodeType {
let response;
if (resource === 'task' && opeation === 'create') {
//https://developer.todoist.com/rest/v1/#create-a-new-task
const content = this.getNodeParameter('content') as string;
const projectId = this.getNodeParameter('project') as number;
const labels = this.getNodeParameter('labels') as [number];
const labels = this.getNodeParameter('labels') as number[];
const options = this.getNodeParameter('options') as IDataObject;
interface IBodyCreateTask {
content: string;
project_id?: number;
parent?: number;
order?: number;
label_ids?: [number];
priority?: number;
due_string?: string;
due_datetime?: string;
due_date?: string;
due_lang?: string;
}
const body: IBodyCreateTask = {
content,
project_id: projectId,
@ -272,15 +268,15 @@ export class Todoist implements INodeType {
};
if (options.dueDateTime) {
body.due_datetime = moment(options.dueDateTime as string).utc().format();
body.due_datetime = options.dueDateTime as string;
}
if (options.dueString) {
body.due_string = options.dueString as string;
}
if (!_.isEmpty(labels)) {
body.label_ids = labels
if (labels !== undefined && labels.length !== 0) {
body.label_ids = labels;
}
try {