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

@ -3,12 +3,12 @@ import {
} from 'n8n-core'; } from 'n8n-core';
import { import {
IDataObject,
ILoadOptionsFunctions, ILoadOptionsFunctions,
INodeExecutionData, INodeExecutionData,
INodePropertyOptions, INodePropertyOptions,
INodeType, INodeType,
INodeTypeDescription, INodeTypeDescription,
IDataObject,
} from 'n8n-workflow'; } from 'n8n-workflow';
import { import {
@ -30,13 +30,13 @@ import {
} from './ProjectInterfaces'; } from './ProjectInterfaces';
import { import {
projectOperations,
projectFields, projectFields,
projectOperations,
} from './ProjectDescription'; } from './ProjectDescription';
import { import {
tagOperations,
tagFields, tagFields,
tagOperations,
} from './TagDescription'; } from './TagDescription';
import { import {
@ -45,7 +45,6 @@ import {
} from './TimeEntryDescription'; } from './TimeEntryDescription';
import * as moment from 'moment-timezone'; import * as moment from 'moment-timezone';
import { boardColumnFields } from '../MondayCom/BoardColumnDescription';
export class Clockify implements INodeType { export class Clockify implements INodeType {
description: INodeTypeDescription = { description: INodeTypeDescription = {
@ -359,14 +358,12 @@ export class Clockify implements INodeType {
body, body,
qs qs
); );
responseData = { success: true };
} }
} }
if (resource === 'tag') { if (resource === 'tag') {
if (operation === 'add') { if (operation === 'create') {
const workspaceId = this.getNodeParameter('workspaceId', i) as string; const workspaceId = this.getNodeParameter('workspaceId', i) as string;
@ -456,8 +453,6 @@ export class Clockify implements INodeType {
body, body,
qs qs
); );
responseData = { success: true };
} }
} }
@ -573,8 +568,6 @@ export class Clockify implements INodeType {
body, body,
qs qs
); );
responseData = { success: true };
} }
} }
} }

View file

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

View file

@ -20,7 +20,7 @@ export interface IMembershipDto {
export interface ITagDto { export interface ITagDto {
id: string; id: string;
name: any; name: any; // tslint:disable-line:no-any
workspaceId: string; workspaceId: string;
archived: boolean; archived: boolean;
} }

View file

@ -1,5 +1,4 @@
import {IHourlyRateDto, IMembershipDto} from "./CommonDtos"; import { IHourlyRateDto, IMembershipDto } from './CommonDtos';
import { INodeExecutionData } from "n8n-workflow";
enum EstimateEnum { enum EstimateEnum {
AUTO = "AUTO", AUTO = "AUTO",
@ -11,7 +10,7 @@ interface IEstimateDto {
type: EstimateEnum; type: EstimateEnum;
} }
export interface IProjectDto{ export interface IProjectDto {
archived: boolean; archived: boolean;
billable: boolean; billable: boolean;
clientId: string; clientId: string;

View file

@ -16,9 +16,9 @@ export const tagOperations = [
}, },
options: [ options: [
{ {
name: 'Add', name: 'Create',
value: 'add', value: 'create',
description: 'Add a tag', description: 'Create a tag',
}, },
{ {
name: 'Delete', name: 'Delete',
@ -59,7 +59,7 @@ export const tagFields = [
'tag', 'tag',
], ],
operation: [ operation: [
'add', 'create',
], ],
}, },
}, },

View file

@ -1,4 +1,4 @@
import {ITimeIntervalDto} from "./CommonDtos"; import { ITimeIntervalDto } from './CommonDtos';
interface ITimeEntriesDurationRequest { interface ITimeEntriesDurationRequest {
start: string; start: string;
@ -18,7 +18,7 @@ export interface ITimeEntryRequest {
timeInterval: ITimeEntriesDurationRequest; timeInterval: ITimeEntriesDurationRequest;
workspaceId: string; workspaceId: string;
isLocked: boolean; isLocked: boolean;
}; }
export interface ITimeEntryDto { export interface ITimeEntryDto {
billable: boolean; billable: boolean;
@ -32,4 +32,3 @@ export interface ITimeEntryDto {
userId: string; userId: string;
workspaceId: string; workspaceId: string;
} }

View file

@ -12,7 +12,7 @@ export interface IUserDto {
defaultWorkspace: string; defaultWorkspace: string;
email: string; email: string;
id: string; id: string;
memberships: IMembershipDto []; memberships: IMembershipDto[];
name: string; name: string;
profilePicture: string; profilePicture: string;
settings: IUserSettingsDto; settings: IUserSettingsDto;

View file

@ -1,7 +1,7 @@
import { IHourlyRateDto, IMembershipDto } from './CommonDtos'; import { IHourlyRateDto, IMembershipDto } from './CommonDtos';
enum AdminOnlyPagesEnum { enum AdminOnlyPagesEnum {
PROJECT ='PROJECT', PROJECT = 'PROJECT',
TEAM = 'TEAM', TEAM = 'TEAM',
REPORTS = 'REPORTS', REPORTS = 'REPORTS',
} }
@ -70,7 +70,7 @@ export interface IWorkspaceDto {
hourlyRate: IHourlyRateDto; hourlyRate: IHourlyRateDto;
id: string; id: string;
imageUrl: string; imageUrl: string;
memberships: IMembershipDto[]; memberships: IMembershipDto[];
name: string; name: string;
workspaceSettings: IWorkspaceSettingsDto; workspaceSettings: IWorkspaceSettingsDto;
} }