From 244b20827b47c67a67478066836277da5459d722 Mon Sep 17 00:00:00 2001 From: ricardo Date: Mon, 19 Apr 2021 11:04:18 -0400 Subject: [PATCH] session 3 --- packages/nodes-base/nodes/Toggl/Toggl.node.ts | 83 ++++++++++++++++++- 1 file changed, 82 insertions(+), 1 deletion(-) diff --git a/packages/nodes-base/nodes/Toggl/Toggl.node.ts b/packages/nodes-base/nodes/Toggl/Toggl.node.ts index 9961d2763e..521f3fd925 100644 --- a/packages/nodes-base/nodes/Toggl/Toggl.node.ts +++ b/packages/nodes-base/nodes/Toggl/Toggl.node.ts @@ -16,7 +16,6 @@ import { } from './GenericFunctions'; import * as moment from 'moment-timezone'; -import { getWorkspaces } from '../Asana/GenericFunctions'; export class Toggl implements INodeType { description: INodeTypeDescription = { @@ -77,6 +76,16 @@ export class Toggl implements INodeType { value: 'start', description: 'Start a time entry', }, + { + name: 'Get', + value: 'get', + description: 'Get a time entry', + }, + { + name: 'Stop', + value: 'stop', + description: 'Stop a time entry', + }, ], default: 'start', description: 'The operation to perform.', @@ -216,6 +225,42 @@ export class Toggl implements INodeType { }, description: 'Time entry duration in seconds.', }, + //here + { + displayName: 'Time Entry ID', + name: 'timeEntryId', + type: 'string', + default: '', + displayOptions: { + show: { + operation: [ + 'get', + ], + resource: [ + 'timeEntry', + ], + }, + }, + description: 'Time entry ID.', + }, + { + displayName: 'Time Entry ID', + name: 'timeEntryId', + type: 'string', + default: '', + displayOptions: { + show: { + operation: [ + 'stop', + ], + resource: [ + 'timeEntry', + ], + }, + }, + description: 'Time entry ID.', + }, + ], }; @@ -285,6 +330,42 @@ export class Toggl implements INodeType { responseData = responseData.data; } + if (operation === 'create') { + const description = this.getNodeParameter('description', i) as string; + const workspaceId= this.getNodeParameter('workspaceId', i) as string; + const startTime = this.getNodeParameter('startTime', i) as string; + const duration = this.getNodeParameter('duration', i) as number; + // -d '{"time_entry":{"description":"Meeting with possible clients","tags":["billed"],"duration":1200,"start":"2013-03-05T07:58:58.000Z","pid":123,"created_with":"curl"}}' \ + const body: IDataObject = { + time_entry: { + description, + duration, + start:startTime, + wid:workspaceId, + created_with: 'n8n', + }, + }; + //POST https://api.track.toggl.com/api/v8/time_entries + + + responseData = await togglApiRequest.call(this, 'POST', '/time_entries', body); + + responseData = responseData.data; + } + if (operation === 'get') { + const timeEntryId = this.getNodeParameter('timeEntryId', i) as string; + //GET https://api.track.toggl.com/api/v8/time_entries/{time_entry_id} + + responseData = await togglApiRequest.call(this, 'GET', `/time_entries/${timeEntryId}`); + responseData = responseData.data; + } + if (operation === 'stop') { + const timeEntryId = this.getNodeParameter('timeEntryId', i) as string; + //PUT https://api.track.toggl.com/api/v8/time_entries/{time_entry_id}/stop + + responseData = await togglApiRequest.call(this, 'PUT', `/time_entries/${timeEntryId}/stop`); + responseData = responseData.data; + } } if (Array.isArray(responseData)) { returnData.push.apply(returnData, responseData as IDataObject[]);