Add Harvest update task operations (#1603)

* Add create/update task in Harvest node

*  Small improvements

Co-authored-by: dali <servfrdali@yahoo.fr>
This commit is contained in:
Ricardo Espinoza 2021-04-02 11:56:45 -04:00 committed by GitHub
parent aab6946e9e
commit 7995bd610d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
11 changed files with 158 additions and 66 deletions

View file

@ -1,6 +1,10 @@
import { INodeProperties } from 'n8n-workflow'; import {
INodeProperties,
} from 'n8n-workflow';
const resource = ['client']; const resource = [
'client',
];
export const clientOperations = [ export const clientOperations = [
{ {
@ -49,7 +53,7 @@ export const clientOperations = [
export const clientFields = [ export const clientFields = [
/* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */
/* client:getAll */ /* client:getAll */
/* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */
{ {
@ -122,7 +126,7 @@ export const clientFields = [
}, },
/* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */
/* client:get */ /* client:get */
/* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */
{ {
displayName: 'Client Id', displayName: 'Client Id',
@ -142,7 +146,7 @@ export const clientFields = [
}, },
/* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */
/* client:delete */ /* client:delete */
/* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */
{ {
displayName: 'Client Id', displayName: 'Client Id',
@ -162,7 +166,7 @@ export const clientFields = [
}, },
/* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */
/* client:create */ /* client:create */
/* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */
{ {
displayName: 'Name', displayName: 'Name',
@ -220,7 +224,7 @@ export const clientFields = [
}, },
/* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */
/* client:update */ /* client:update */
/* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */
{ {
displayName: 'Client Id', displayName: 'Client Id',

View file

@ -1,6 +1,10 @@
import { INodeProperties } from 'n8n-workflow'; import {
INodeProperties,
} from 'n8n-workflow';
const resource = ['company']; const resource = [
'company',
];
export const companyOperations = [ export const companyOperations = [
{ {

View file

@ -1,6 +1,10 @@
import { INodeProperties } from 'n8n-workflow'; import {
INodeProperties,
} from 'n8n-workflow';
const resource = ['contact']; const resource = [
'contact',
];
export const contactOperations = [ export const contactOperations = [
{ {
@ -48,7 +52,7 @@ export const contactOperations = [
export const contactFields = [ export const contactFields = [
/* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */
/* contact:getAll */ /* contact:getAll */
/* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */
{ {
@ -121,7 +125,7 @@ export const contactFields = [
}, },
/* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */
/* contact:get */ /* contact:get */
/* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */
{ {
displayName: 'Contact Id', displayName: 'Contact Id',
@ -141,7 +145,7 @@ export const contactFields = [
}, },
/* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */
/* contact:delete */ /* contact:delete */
/* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */
{ {
displayName: 'Contact Id', displayName: 'Contact Id',
@ -161,7 +165,7 @@ export const contactFields = [
}, },
/* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */
/* contact:create */ /* contact:create */
/* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */
{ {
displayName: 'First Name', displayName: 'First Name',
@ -256,7 +260,7 @@ export const contactFields = [
}, },
/* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */
/* contact:update */ /* contact:update */
/* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */
{ {
displayName: 'Contact Id', displayName: 'Contact Id',

View file

@ -1,6 +1,10 @@
import { INodeProperties } from 'n8n-workflow'; import {
INodeProperties,
} from 'n8n-workflow';
const resource = ['estimate']; const resource = [
'estimate',
];
export const estimateOperations = [ export const estimateOperations = [
{ {
@ -48,7 +52,7 @@ export const estimateOperations = [
export const estimateFields = [ export const estimateFields = [
/* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */
/* estimate:getAll */ /* estimate:getAll */
/* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */
{ {
@ -152,7 +156,7 @@ export const estimateFields = [
}, },
/* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */
/* estimate:get */ /* estimate:get */
/* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */
{ {
displayName: 'Estimate Id', displayName: 'Estimate Id',
@ -172,7 +176,7 @@ export const estimateFields = [
}, },
/* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */
/* estimate:delete */ /* estimate:delete */
/* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */
{ {
displayName: 'Estimate Id', displayName: 'Estimate Id',
@ -192,7 +196,7 @@ export const estimateFields = [
}, },
/* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */
/* estimate:create */ /* estimate:create */
/* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */
{ {
displayName: 'Client Id', displayName: 'Client Id',
@ -292,7 +296,7 @@ export const estimateFields = [
}, },
/* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */
/* estimate:update */ /* estimate:update */
/* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */
{ {
displayName: 'Invoice Id', displayName: 'Invoice Id',

View file

@ -1,6 +1,10 @@
import { INodeProperties } from 'n8n-workflow'; import {
INodeProperties,
} from 'n8n-workflow';
const resource = ['expense']; const resource = [
'expense',
];
export const expenseOperations = [ export const expenseOperations = [
{ {
@ -48,7 +52,7 @@ export const expenseOperations = [
export const expenseFields = [ export const expenseFields = [
/* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */
/* expense:getAll */ /* expense:getAll */
/* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */
{ {
@ -166,7 +170,7 @@ export const expenseFields = [
}, },
/* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */
/* expense:get */ /* expense:get */
/* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */
{ {
displayName: 'Expense Id', displayName: 'Expense Id',
@ -186,7 +190,7 @@ export const expenseFields = [
}, },
/* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */
/* expense:delete */ /* expense:delete */
/* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */
{ {
displayName: 'Expense Id', displayName: 'Expense Id',
@ -206,7 +210,7 @@ export const expenseFields = [
}, },
/* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */
/* expense:create */ /* expense:create */
/* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */
{ {
displayName: 'Project Id', displayName: 'Project Id',
@ -310,7 +314,7 @@ export const expenseFields = [
}, },
/* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */
/* invoice:update */ /* invoice:update */
/* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */
{ {
displayName: 'Invoice Id', displayName: 'Invoice Id',

View file

@ -54,6 +54,7 @@ import {
taskFields, taskFields,
taskOperations, taskOperations,
} from './TaskDescription'; } from './TaskDescription';
import { import {
timeEntryFields, timeEntryFields,
timeEntryOperations, timeEntryOperations,
@ -693,6 +694,37 @@ export class Harvest implements INodeType {
const responseData: IDataObject[] = await getAllResource.call(this, 'tasks', i); const responseData: IDataObject[] = await getAllResource.call(this, 'tasks', i);
returnData.push.apply(returnData, responseData); returnData.push.apply(returnData, responseData);
} else if (operation === 'create') {
// ----------------------------------
// create
// ----------------------------------
requestMethod = 'POST';
endpoint = 'tasks';
body.name = this.getNodeParameter('name', i) as string;
const additionalFields = this.getNodeParameter('additionalFields', i) as IDataObject;
Object.assign(body, additionalFields);
const responseData = await harvestApiRequest.call(this, requestMethod, qs, endpoint, body);
returnData.push(responseData);
} else if (operation === 'update') {
// ----------------------------------
// update
// ----------------------------------
requestMethod = 'PATCH';
const id = this.getNodeParameter('id', i) as string;
endpoint = `tasks/${id}`;
const updateFields = this.getNodeParameter('updateFields', i) as IDataObject;
Object.assign(qs, updateFields);
const responseData = await harvestApiRequest.call(this, requestMethod, qs, endpoint, body);
returnData.push(responseData);
} else if (operation === 'delete') { } else if (operation === 'delete') {
// ---------------------------------- // ----------------------------------
// delete // delete

View file

@ -1,6 +1,10 @@
import { INodeProperties } from 'n8n-workflow'; import {
INodeProperties,
} from 'n8n-workflow';
const resource = ['invoice']; const resource = [
'invoice',
];
export const invoiceOperations = [ export const invoiceOperations = [
{ {
@ -48,7 +52,7 @@ export const invoiceOperations = [
export const invoiceFields = [ export const invoiceFields = [
/* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */
/* invoice:getAll */ /* invoice:getAll */
/* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */
{ {
@ -177,7 +181,7 @@ export const invoiceFields = [
}, },
/* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */
/* invoice:get */ /* invoice:get */
/* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */
{ {
displayName: 'Invoice Id', displayName: 'Invoice Id',
@ -197,7 +201,7 @@ export const invoiceFields = [
}, },
/* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */
/* invoice:delete */ /* invoice:delete */
/* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */
{ {
displayName: 'Invoice Id', displayName: 'Invoice Id',
@ -217,7 +221,7 @@ export const invoiceFields = [
}, },
/* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */
/* invoice:create */ /* invoice:create */
/* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */
{ {
displayName: 'Client Id', displayName: 'Client Id',
@ -345,7 +349,7 @@ export const invoiceFields = [
}, },
/* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */
/* invoice:update */ /* invoice:update */
/* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */
{ {
displayName: 'Invoice Id', displayName: 'Invoice Id',

View file

@ -1,6 +1,10 @@
import { INodeProperties } from 'n8n-workflow'; import {
INodeProperties,
} from 'n8n-workflow';
const resource = ['project']; const resource = [
'project',
];
export const projectOperations = [ export const projectOperations = [
{ {
@ -48,7 +52,7 @@ export const projectOperations = [
export const projectFields = [ export const projectFields = [
/* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */
/* projects:getAll */ /* projects:getAll */
/* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */
{ {
@ -138,7 +142,7 @@ export const projectFields = [
}, },
/* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */
/* project:get */ /* project:get */
/* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */
{ {
displayName: 'Project Id', displayName: 'Project Id',
@ -158,7 +162,7 @@ export const projectFields = [
}, },
/* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */
/* project:delete */ /* project:delete */
/* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */
{ {
displayName: 'Project Id', displayName: 'Project Id',
@ -178,7 +182,7 @@ export const projectFields = [
}, },
/* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */
/* project:create */ /* project:create */
/* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */
{ {
displayName: 'Name', displayName: 'Name',
@ -399,7 +403,7 @@ export const projectFields = [
}, },
/* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */
/* project:update */ /* project:update */
/* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */
{ {
displayName: 'Project Id', displayName: 'Project Id',

View file

@ -1,5 +1,11 @@
import { INodeProperties } from 'n8n-workflow'; import {
const resource = ['task']; INodeProperties
} from 'n8n-workflow';
const resource = [
'task',
];
export const taskOperations = [ export const taskOperations = [
{ {
displayName: 'Operation', displayName: 'Operation',
@ -46,7 +52,7 @@ export const taskOperations = [
export const taskFields = [ export const taskFields = [
/* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */
/* task:getAll */ /* task:getAll */
/* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */
{ {
displayName: 'Return All', displayName: 'Return All',
@ -128,7 +134,7 @@ export const taskFields = [
}, },
/* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */
/* task:get */ /* task:get */
/* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */
{ {
displayName: 'Task Id', displayName: 'Task Id',
@ -148,7 +154,7 @@ export const taskFields = [
}, },
/* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */
/* task:delete */ /* task:delete */
/* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */
{ {
displayName: 'Task Id', displayName: 'Task Id',
@ -164,11 +170,11 @@ export const taskFields = [
resource, resource,
}, },
}, },
description: 'The ID of the task you wan to delete.', description: 'The ID of the task you want to delete.',
}, },
/* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */
/* task:create */ /* task:create */
/* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */
{ {
displayName: 'Name', displayName: 'Name',
@ -205,14 +211,14 @@ export const taskFields = [
displayName: 'Billable By Default', displayName: 'Billable By Default',
name: 'billable_by_default', name: 'billable_by_default',
type: 'boolean', type: 'boolean',
default: '', default: true,
description: 'Used in determining whether default tasks should be marked billable when creating a new project. Defaults to true.', description: 'Used in determining whether default tasks should be marked billable when creating a new project. Defaults to true.',
}, },
{ {
displayName: 'Default Hourly Rate', displayName: 'Default Hourly Rate',
name: 'default_hourly_rate', name: 'default_hourly_rate',
type: 'string', type: 'number',
default: '0', default: 0,
description: 'The default hourly rate to use for this task when it is added to a project. Defaults to 0.', description: 'The default hourly rate to use for this task when it is added to a project. Defaults to 0.',
}, },
{ {
@ -232,8 +238,24 @@ export const taskFields = [
], ],
}, },
/* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */
/* task:update */ /* task:update */
/* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */
{
displayName: 'Task ID',
name: 'id',
type: 'string',
default: '',
required: true,
displayOptions: {
show: {
operation: [
'update',
],
resource,
},
},
description: 'The ID of the task you want to update.',
},
{ {
displayName: 'Update Fields', displayName: 'Update Fields',
name: 'updateFields', name: 'updateFields',
@ -260,8 +282,8 @@ export const taskFields = [
{ {
displayName: 'Default Hourly Rate', displayName: 'Default Hourly Rate',
name: 'default_hourly_rate', name: 'default_hourly_rate',
type: 'string', type: 'number',
default: '0', default: 0,
description: 'The default hourly rate to use for this task when it is added to a project. Defaults to 0.', description: 'The default hourly rate to use for this task when it is added to a project. Defaults to 0.',
}, },
{ {

View file

@ -1,5 +1,11 @@
import { INodeProperties } from 'n8n-workflow'; import {
export const resource = ['timeEntry']; INodeProperties,
} from 'n8n-workflow';
export const resource = [
'timeEntry',
];
export const timeEntryOperations = [ export const timeEntryOperations = [
{ {
displayName: 'Operation', displayName: 'Operation',

View file

@ -1,6 +1,10 @@
import { INodeProperties } from 'n8n-workflow'; import {
INodeProperties,
} from 'n8n-workflow';
const resource = ['user']; const resource = [
'user',
];
export const userOperations = [ export const userOperations = [
{ {
@ -54,7 +58,7 @@ export const userOperations = [
export const userFields = [ export const userFields = [
/* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */
/* user:getAll */ /* user:getAll */
/* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */
{ {
@ -137,7 +141,7 @@ export const userFields = [
}, },
/* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */
/* user:get */ /* user:get */
/* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */
{ {
displayName: 'User Id', displayName: 'User Id',
@ -157,7 +161,7 @@ export const userFields = [
}, },
/* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */
/* user:delete */ /* user:delete */
/* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */
{ {
displayName: 'User Id', displayName: 'User Id',
@ -177,7 +181,7 @@ export const userFields = [
}, },
/* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */
/* user:create */ /* user:create */
/* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */
{ {
displayName: 'First Name', displayName: 'First Name',
@ -344,7 +348,7 @@ export const userFields = [
/* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */
/* user:update */ /* user:update */
/* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */
{ {
displayName: 'Time Entry Id', displayName: 'Time Entry Id',