Minor improvements to Clockify-Node

This commit is contained in:
Jan Oberhauser
2020-10-04 16:32:12 +02:00
parent 3a73493aeb
commit a25229ace9
8 changed files with 30 additions and 39 deletions

View File

@@ -1,6 +1,6 @@
import * as moment from 'moment-timezone';
import {IPollFunctions} from 'n8n-core';
import { IPollFunctions } from 'n8n-core';
import {
IDataObject,
ILoadOptionsFunctions,
@@ -69,16 +69,16 @@ export class ClockifyTrigger implements INodeType {
methods = {
loadOptions: {
async listWorkspaces(this: ILoadOptionsFunctions) : Promise<INodePropertyOptions[]> {
const rtv : INodePropertyOptions[] = [];
const workspaces: IWorkspaceDto[] = await clockifyApiRequest.call(this,'GET', 'workspaces');
if(undefined !== workspaces) {
async listWorkspaces(this: ILoadOptionsFunctions): Promise<INodePropertyOptions[]> {
const rtv: INodePropertyOptions[] = [];
const workspaces: IWorkspaceDto[] = await clockifyApiRequest.call(this, 'GET', 'workspaces');
if (undefined !== workspaces) {
workspaces.forEach(value => {
rtv.push(
{
name: value.name,
value: value.id,
});
{
name: value.name,
value: value.id,
});
});
}
return rtv;
@@ -89,7 +89,7 @@ export class ClockifyTrigger implements INodeType {
async poll(this: IPollFunctions): Promise<INodeExecutionData[][] | null> {
const webhookData = this.getWorkflowStaticData('node');
const triggerField = this.getNodeParameter('watchField') as EntryTypeEnum;
const workspaceId = this.getNodeParameter('workspaceId');
const workspaceId = this.getNodeParameter('workspaceId');
if (!webhookData.userId) {
// Cache the user-id that we do not have to request it every time
@@ -97,12 +97,12 @@ export class ClockifyTrigger implements INodeType {
webhookData.userId = userInfo.id;
}
const qs : IDataObject = {};
const qs: IDataObject = {};
let resource: string;
let result = null;
switch (triggerField) {
case EntryTypeEnum.NEW_TIME_ENTRY :
case EntryTypeEnum.NEW_TIME_ENTRY:
default:
const workflowTimezone = this.getTimezone();
resource = `workspaces/${workspaceId}/user/${webhookData.userId}/time-entries`;
@@ -110,10 +110,10 @@ export class ClockifyTrigger implements INodeType {
qs.end = moment().tz(workflowTimezone).format('YYYY-MM-DDTHH:mm:ss') + 'Z';
qs.hydrated = true;
qs['in-progress'] = false;
break;
break;
}
result = await clockifyApiRequest.call(this, 'GET', resource, {}, qs );
result = await clockifyApiRequest.call(this, 'GET', resource, {}, qs);
webhookData.lastTimeChecked = qs.end;
if (Array.isArray(result) && result.length !== 0) {