session 3

This commit is contained in:
ricardo 2021-04-19 11:04:18 -04:00
parent 0e36380353
commit 244b20827b

View file

@ -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[]);