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

View file

@ -10,11 +10,22 @@ import {
INodePropertyOptions, INodePropertyOptions,
} from 'n8n-workflow'; } from 'n8n-workflow';
import { import {
todoistApiRequest todoistApiRequest,
} from './GenericFunctions'; } 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 { export class Todoist implements INodeType {
@ -50,7 +61,7 @@ export class Todoist implements INodeType {
description: 'Task resource.', description: 'Task resource.',
}, },
], ],
default: '', default: 'task',
required: true, required: true,
description: 'Resource to consume.', description: 'Resource to consume.',
}, },
@ -89,7 +100,7 @@ export class Todoist implements INodeType {
'task', 'task',
], ],
operation: [ operation: [
'create' 'create',
] ]
}, },
}, },
@ -109,7 +120,7 @@ export class Todoist implements INodeType {
'task', 'task',
], ],
operation: [ operation: [
'create' 'create',
] ]
}, },
}, },
@ -130,7 +141,7 @@ export class Todoist implements INodeType {
'task', 'task',
], ],
operation: [ operation: [
'create' 'create',
] ]
}, },
}, },
@ -150,7 +161,7 @@ export class Todoist implements INodeType {
'task', 'task',
], ],
operation: [ operation: [
'create' 'create',
] ]
}, },
}, },
@ -162,7 +173,7 @@ export class Todoist implements INodeType {
typeOptions: { typeOptions: {
numberStepSize: 1, numberStepSize: 1,
maxValue: 4, maxValue: 4,
minValue: 1 minValue: 1,
}, },
default: 1, default: 1,
description: 'Task priority from 1 (normal) to 4 (urgent).', 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 // 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; let response;
if (resource === 'task' && opeation === 'create') { if (resource === 'task' && opeation === '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') as string; const content = this.getNodeParameter('content') as string;
const projectId = this.getNodeParameter('project') as number; 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; 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 = { const body: IBodyCreateTask = {
content, content,
project_id: projectId, project_id: projectId,
@ -272,15 +268,15 @@ export class Todoist implements INodeType {
}; };
if (options.dueDateTime) { if (options.dueDateTime) {
body.due_datetime = moment(options.dueDateTime as string).utc().format(); 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 (!_.isEmpty(labels)) { if (labels !== undefined && labels.length !== 0) {
body.label_ids = labels body.label_ids = labels;
} }
try { try {