1
1
mirror of https://github.com/n8n-io/n8n.git synced 2024-11-11 12:26:30 +03:00

Improved Clickify-Node

This commit is contained in:
Jan Oberhauser 2020-02-21 11:41:08 +01:00
parent 78bf915e65
commit 5548e4e794
7 changed files with 49 additions and 47 deletions

View File

@ -1,3 +1,5 @@
import * as moment from 'moment-timezone';
import {IPollFunctions} from 'n8n-core';
import {
IDataObject,
@ -12,22 +14,21 @@ import {
clockifyApiRequest,
} from './GenericFunctions';
import {IWorkspaceDto} from "./WorkpaceInterfaces";
import {EntryTypeEnum} from "./EntryTypeEnum";
import {ICurrentUserDto} from "./UserDtos";
import * as moment from "moment";
import { EntryTypeEnum } from './EntryTypeEnum';
import { ICurrentUserDto } from './UserDtos';
import { IWorkspaceDto } from './WorkpaceInterfaces';
export class ClockifyTrigger implements INodeType {
description: INodeTypeDescription = {
displayName: 'Clockify Event',
icon: 'file:images/clockify-mark-blue.png',
displayName: 'Clockify Trigger',
icon: 'file:clockify.png',
name: 'clockifyTrigger',
group: ['trigger'],
version: 1,
description: 'Watches Clockify For Events',
defaults: {
name: 'Clockify Event',
name: 'Clockify Trigger',
color: '#00FF00',
},
inputs: [],
@ -38,6 +39,7 @@ export class ClockifyTrigger implements INodeType {
required: true,
}
],
polling: true,
properties: [
{
displayName: 'Workspace',
@ -60,7 +62,7 @@ export class ClockifyTrigger implements INodeType {
}
],
required: true,
default: '',
default: EntryTypeEnum.NEW_TIME_ENTRY,
},
]
};
@ -89,7 +91,12 @@ export class ClockifyTrigger implements INodeType {
const triggerField = this.getNodeParameter('watchField') as EntryTypeEnum;
const workspaceId = this.getNodeParameter('workspaceId');
const userInfo : ICurrentUserDto = await clockifyApiRequest.call(this,'GET', 'user');
if (!webhookData.userId) {
// Cache the user-id that we do not have to request it every time
const userInfo: ICurrentUserDto = await clockifyApiRequest.call(this, 'GET', 'user');
webhookData.userId = userInfo.id;
}
const qs : IDataObject = {};
let resource: string;
let result = null;
@ -97,21 +104,18 @@ export class ClockifyTrigger implements INodeType {
switch (triggerField) {
case EntryTypeEnum.NEW_TIME_ENTRY :
default:
resource = `workspaces/${workspaceId}/user/${userInfo.id}/time-entries`;
const workflowTimezone = this.getTimezone();
resource = `workspaces/${workspaceId}/user/${webhookData.userId}/time-entries`;
qs.start = webhookData.lastTimeChecked;
qs.end = moment().toISOString();
qs.end = moment().tz(workflowTimezone).format('YYYY-MM-DDTHH:mm:SS') + 'Z';
qs.hydrated = true;
qs['in-progress'] = false;
break;
}
try {
result = await clockifyApiRequest.call(this, 'GET', resource, {}, qs );
webhookData.lastTimeChecked = qs.end_date;
}
catch( e ) {
throw new Error(`Clockify Exception: ${e}`);
}
result = await clockifyApiRequest.call(this, 'GET', resource, {}, qs );
webhookData.lastTimeChecked = qs.end;
if (Array.isArray(result) && result.length !== 0) {
result = [this.helpers.returnJsonArray(result)];
}

View File

@ -4,10 +4,10 @@ export interface IHourlyRateDto {
}
enum MembershipStatusEnum {
PENDING = "PENDING",
ACTIVE = "ACTIVE",
DECLINED = "DECLINED",
INACTIVE = "INACTIVE"
PENDING = 'PENDING',
ACTIVE = 'ACTIVE',
DECLINED = 'DECLINED',
INACTIVE = 'INACTIVE'
}
export interface IMembershipDto {

View File

@ -2,16 +2,16 @@ import { OptionsWithUri } from 'request';
import {
ILoadOptionsFunctions,
IPollFunctions
} from "n8n-core";
} from 'n8n-core';
import {IDataObject} from "n8n-workflow";
import { IDataObject } from 'n8n-workflow';
export async function clockifyApiRequest(this: ILoadOptionsFunctions | IPollFunctions, method: string, resource: string, body: any = {}, qs: IDataObject = {}, uri?: string, option: IDataObject = {}): Promise<any> { // tslint:disable-line:no-any
const credentials = this.getCredentials('clockifyApi');
if (credentials === undefined) {
throw new Error('No credentials got returned!');
}
const BASE_URL = `https://api.clockify.me/api/v1`;
const BASE_URL = 'https://api.clockify.me/api/v1';
const options: OptionsWithUri = {
headers: {

View File

@ -1,4 +1,4 @@
import {IMembershipDto} from "./CommonDtos";
import { IMembershipDto } from './CommonDtos';
enum UserStatusEnum {
ACTIVE, PENDING_EMAIL_VERIFICATION, DELETED

View File

@ -1,31 +1,31 @@
import {IHourlyRateDto, IMembershipDto} from "./CommonDtos";
import { IHourlyRateDto, IMembershipDto } from './CommonDtos';
enum AdminOnlyPagesEnum {
PROJECT ="PROJECT",
TEAM = "TEAM",
REPORTS = "REPORTS"
PROJECT ='PROJECT',
TEAM = 'TEAM',
REPORTS = 'REPORTS',
}
enum DaysOfWeekEnum {
MONDAY = "MONDAY",
TUESDAY = "TUESDAY",
WEDNESDAY = "WEDNESDAY",
THURSDAY = "THURSDAY",
FRIDAY = "FRIDAY",
SATURDAY = "SATURDAY",
SUNDAY = "SUNDAY"
MONDAY = 'MONDAY',
TUESDAY = 'TUESDAY',
WEDNESDAY = 'WEDNESDAY',
THURSDAY = 'THURSDAY',
FRIDAY = 'FRIDAY',
SATURDAY = 'SATURDAY',
SUNDAY = 'SUNDAY',
}
enum DatePeriodEnum {
DAYS="DAYS",
WEEKS = "WEEKS",
MONTHS = "MONTHS"
DAYS = 'DAYS',
WEEKS = 'WEEKS',
MONTHS = 'MONTHS',
}
enum AutomaticLockTypeEnum {
WEEKLY = "WEEKLY",
MONTHLY = "MONTHLY",
OLDER_THAN = "OLDER_THAN"
WEEKLY = 'WEEKLY',
MONTHLY = 'MONTHLY',
OLDER_THAN = 'OLDER_THAN',
}
interface IAutomaticLockDto {
@ -74,4 +74,3 @@ export interface IWorkspaceDto {
name: string;
workspaceSettings: IWorkspaceSettingsDto;
}

View File

Before

Width:  |  Height:  |  Size: 5.8 KiB

After

Width:  |  Height:  |  Size: 5.8 KiB

View File

@ -37,7 +37,7 @@
"dist/credentials/ChargebeeApi.credentials.js",
"dist/credentials/ClearbitApi.credentials.js",
"dist/credentials/ClickUpApi.credentials.js",
"dist/credentials/ClockifyApi.credentials.js",
"dist/credentials/ClockifyApi.credentials.js",
"dist/credentials/CodaApi.credentials.js",
"dist/credentials/CopperApi.credentials.js",
"dist/credentials/DisqusApi.credentials.js",
@ -119,7 +119,7 @@
"dist/nodes/Clearbit/Clearbit.node.js",
"dist/nodes/ClickUp/ClickUp.node.js",
"dist/nodes/ClickUp/ClickUpTrigger.node.js",
"dist/nodes/Clockify/ClockifyTrigger.node.js",
"dist/nodes/Clockify/ClockifyTrigger.node.js",
"dist/nodes/Coda/Coda.node.js",
"dist/nodes/Copper/CopperTrigger.node.js",
"dist/nodes/Cron.node.js",
@ -295,4 +295,3 @@
]
}
}