From 7995bd610d63f5e54b363b24f3510ce2f2aaf816 Mon Sep 17 00:00:00 2001 From: Ricardo Espinoza Date: Fri, 2 Apr 2021 11:56:45 -0400 Subject: [PATCH] :sparkles: Add Harvest update task operations (#1603) * Add create/update task in Harvest node * :zap: Small improvements Co-authored-by: dali --- .../nodes/Harvest/ClientDescription.ts | 18 ++++--- .../nodes/Harvest/CompanyDescription.ts | 8 +++- .../nodes/Harvest/ContactDescription.ts | 18 ++++--- .../nodes/Harvest/EstimateDescription.ts | 18 ++++--- .../nodes/Harvest/ExpenseDescription.ts | 18 ++++--- .../nodes-base/nodes/Harvest/Harvest.node.ts | 32 +++++++++++++ .../nodes/Harvest/InvoiceDescription.ts | 18 ++++--- .../nodes/Harvest/ProjectDescription.ts | 18 ++++--- .../nodes/Harvest/TaskDescription.ts | 48 ++++++++++++++----- .../nodes/Harvest/TimeEntryDescription.ts | 10 +++- .../nodes/Harvest/UserDescription.ts | 18 ++++--- 11 files changed, 158 insertions(+), 66 deletions(-) diff --git a/packages/nodes-base/nodes/Harvest/ClientDescription.ts b/packages/nodes-base/nodes/Harvest/ClientDescription.ts index 482f04d4d3..61ae3f514e 100644 --- a/packages/nodes-base/nodes/Harvest/ClientDescription.ts +++ b/packages/nodes-base/nodes/Harvest/ClientDescription.ts @@ -1,6 +1,10 @@ -import { INodeProperties } from 'n8n-workflow'; +import { + INodeProperties, +} from 'n8n-workflow'; -const resource = ['client']; +const resource = [ + 'client', +]; export const clientOperations = [ { @@ -49,7 +53,7 @@ export const clientOperations = [ export const clientFields = [ /* -------------------------------------------------------------------------- */ - /* client:getAll */ + /* client:getAll */ /* -------------------------------------------------------------------------- */ { @@ -122,7 +126,7 @@ export const clientFields = [ }, /* -------------------------------------------------------------------------- */ - /* client:get */ + /* client:get */ /* -------------------------------------------------------------------------- */ { displayName: 'Client Id', @@ -142,7 +146,7 @@ export const clientFields = [ }, /* -------------------------------------------------------------------------- */ - /* client:delete */ + /* client:delete */ /* -------------------------------------------------------------------------- */ { displayName: 'Client Id', @@ -162,7 +166,7 @@ export const clientFields = [ }, /* -------------------------------------------------------------------------- */ - /* client:create */ + /* client:create */ /* -------------------------------------------------------------------------- */ { displayName: 'Name', @@ -220,7 +224,7 @@ export const clientFields = [ }, /* -------------------------------------------------------------------------- */ - /* client:update */ + /* client:update */ /* -------------------------------------------------------------------------- */ { displayName: 'Client Id', diff --git a/packages/nodes-base/nodes/Harvest/CompanyDescription.ts b/packages/nodes-base/nodes/Harvest/CompanyDescription.ts index 917b29deb6..34300dbf99 100644 --- a/packages/nodes-base/nodes/Harvest/CompanyDescription.ts +++ b/packages/nodes-base/nodes/Harvest/CompanyDescription.ts @@ -1,6 +1,10 @@ -import { INodeProperties } from 'n8n-workflow'; +import { + INodeProperties, +} from 'n8n-workflow'; -const resource = ['company']; +const resource = [ + 'company', +]; export const companyOperations = [ { diff --git a/packages/nodes-base/nodes/Harvest/ContactDescription.ts b/packages/nodes-base/nodes/Harvest/ContactDescription.ts index 3c17745e31..5c71f7092c 100644 --- a/packages/nodes-base/nodes/Harvest/ContactDescription.ts +++ b/packages/nodes-base/nodes/Harvest/ContactDescription.ts @@ -1,6 +1,10 @@ -import { INodeProperties } from 'n8n-workflow'; +import { + INodeProperties, +} from 'n8n-workflow'; -const resource = ['contact']; +const resource = [ + 'contact', +]; export const contactOperations = [ { @@ -48,7 +52,7 @@ export const contactOperations = [ export const contactFields = [ /* -------------------------------------------------------------------------- */ - /* contact:getAll */ + /* contact:getAll */ /* -------------------------------------------------------------------------- */ { @@ -121,7 +125,7 @@ export const contactFields = [ }, /* -------------------------------------------------------------------------- */ - /* contact:get */ + /* contact:get */ /* -------------------------------------------------------------------------- */ { displayName: 'Contact Id', @@ -141,7 +145,7 @@ export const contactFields = [ }, /* -------------------------------------------------------------------------- */ - /* contact:delete */ + /* contact:delete */ /* -------------------------------------------------------------------------- */ { displayName: 'Contact Id', @@ -161,7 +165,7 @@ export const contactFields = [ }, /* -------------------------------------------------------------------------- */ - /* contact:create */ + /* contact:create */ /* -------------------------------------------------------------------------- */ { displayName: 'First Name', @@ -256,7 +260,7 @@ export const contactFields = [ }, /* -------------------------------------------------------------------------- */ - /* contact:update */ + /* contact:update */ /* -------------------------------------------------------------------------- */ { displayName: 'Contact Id', diff --git a/packages/nodes-base/nodes/Harvest/EstimateDescription.ts b/packages/nodes-base/nodes/Harvest/EstimateDescription.ts index f827a27d8b..a898738cba 100644 --- a/packages/nodes-base/nodes/Harvest/EstimateDescription.ts +++ b/packages/nodes-base/nodes/Harvest/EstimateDescription.ts @@ -1,6 +1,10 @@ -import { INodeProperties } from 'n8n-workflow'; +import { + INodeProperties, +} from 'n8n-workflow'; -const resource = ['estimate']; +const resource = [ + 'estimate', +]; export const estimateOperations = [ { @@ -48,7 +52,7 @@ export const estimateOperations = [ export const estimateFields = [ /* -------------------------------------------------------------------------- */ - /* estimate:getAll */ + /* estimate:getAll */ /* -------------------------------------------------------------------------- */ { @@ -152,7 +156,7 @@ export const estimateFields = [ }, /* -------------------------------------------------------------------------- */ - /* estimate:get */ + /* estimate:get */ /* -------------------------------------------------------------------------- */ { displayName: 'Estimate Id', @@ -172,7 +176,7 @@ export const estimateFields = [ }, /* -------------------------------------------------------------------------- */ - /* estimate:delete */ + /* estimate:delete */ /* -------------------------------------------------------------------------- */ { displayName: 'Estimate Id', @@ -192,7 +196,7 @@ export const estimateFields = [ }, /* -------------------------------------------------------------------------- */ - /* estimate:create */ + /* estimate:create */ /* -------------------------------------------------------------------------- */ { displayName: 'Client Id', @@ -292,7 +296,7 @@ export const estimateFields = [ }, /* -------------------------------------------------------------------------- */ - /* estimate:update */ + /* estimate:update */ /* -------------------------------------------------------------------------- */ { displayName: 'Invoice Id', diff --git a/packages/nodes-base/nodes/Harvest/ExpenseDescription.ts b/packages/nodes-base/nodes/Harvest/ExpenseDescription.ts index a32e836c4b..d9b21bec35 100644 --- a/packages/nodes-base/nodes/Harvest/ExpenseDescription.ts +++ b/packages/nodes-base/nodes/Harvest/ExpenseDescription.ts @@ -1,6 +1,10 @@ -import { INodeProperties } from 'n8n-workflow'; +import { + INodeProperties, +} from 'n8n-workflow'; -const resource = ['expense']; +const resource = [ + 'expense', +]; export const expenseOperations = [ { @@ -48,7 +52,7 @@ export const expenseOperations = [ export const expenseFields = [ /* -------------------------------------------------------------------------- */ - /* expense:getAll */ + /* expense:getAll */ /* -------------------------------------------------------------------------- */ { @@ -166,7 +170,7 @@ export const expenseFields = [ }, /* -------------------------------------------------------------------------- */ - /* expense:get */ + /* expense:get */ /* -------------------------------------------------------------------------- */ { displayName: 'Expense Id', @@ -186,7 +190,7 @@ export const expenseFields = [ }, /* -------------------------------------------------------------------------- */ - /* expense:delete */ + /* expense:delete */ /* -------------------------------------------------------------------------- */ { displayName: 'Expense Id', @@ -206,7 +210,7 @@ export const expenseFields = [ }, /* -------------------------------------------------------------------------- */ - /* expense:create */ + /* expense:create */ /* -------------------------------------------------------------------------- */ { displayName: 'Project Id', @@ -310,7 +314,7 @@ export const expenseFields = [ }, /* -------------------------------------------------------------------------- */ - /* invoice:update */ + /* invoice:update */ /* -------------------------------------------------------------------------- */ { displayName: 'Invoice Id', diff --git a/packages/nodes-base/nodes/Harvest/Harvest.node.ts b/packages/nodes-base/nodes/Harvest/Harvest.node.ts index b7edc1a7d5..52f9a9b6cb 100644 --- a/packages/nodes-base/nodes/Harvest/Harvest.node.ts +++ b/packages/nodes-base/nodes/Harvest/Harvest.node.ts @@ -54,6 +54,7 @@ import { taskFields, taskOperations, } from './TaskDescription'; + import { timeEntryFields, timeEntryOperations, @@ -693,6 +694,37 @@ export class Harvest implements INodeType { const responseData: IDataObject[] = await getAllResource.call(this, 'tasks', i); 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') { // ---------------------------------- // delete diff --git a/packages/nodes-base/nodes/Harvest/InvoiceDescription.ts b/packages/nodes-base/nodes/Harvest/InvoiceDescription.ts index 4778507a1a..8d2822878d 100644 --- a/packages/nodes-base/nodes/Harvest/InvoiceDescription.ts +++ b/packages/nodes-base/nodes/Harvest/InvoiceDescription.ts @@ -1,6 +1,10 @@ -import { INodeProperties } from 'n8n-workflow'; +import { + INodeProperties, +} from 'n8n-workflow'; -const resource = ['invoice']; +const resource = [ + 'invoice', +]; export const invoiceOperations = [ { @@ -48,7 +52,7 @@ export const invoiceOperations = [ export const invoiceFields = [ /* -------------------------------------------------------------------------- */ - /* invoice:getAll */ + /* invoice:getAll */ /* -------------------------------------------------------------------------- */ { @@ -177,7 +181,7 @@ export const invoiceFields = [ }, /* -------------------------------------------------------------------------- */ - /* invoice:get */ + /* invoice:get */ /* -------------------------------------------------------------------------- */ { displayName: 'Invoice Id', @@ -197,7 +201,7 @@ export const invoiceFields = [ }, /* -------------------------------------------------------------------------- */ - /* invoice:delete */ + /* invoice:delete */ /* -------------------------------------------------------------------------- */ { displayName: 'Invoice Id', @@ -217,7 +221,7 @@ export const invoiceFields = [ }, /* -------------------------------------------------------------------------- */ - /* invoice:create */ + /* invoice:create */ /* -------------------------------------------------------------------------- */ { displayName: 'Client Id', @@ -345,7 +349,7 @@ export const invoiceFields = [ }, /* -------------------------------------------------------------------------- */ - /* invoice:update */ + /* invoice:update */ /* -------------------------------------------------------------------------- */ { displayName: 'Invoice Id', diff --git a/packages/nodes-base/nodes/Harvest/ProjectDescription.ts b/packages/nodes-base/nodes/Harvest/ProjectDescription.ts index 6a4b0d4202..3f7a40dd08 100644 --- a/packages/nodes-base/nodes/Harvest/ProjectDescription.ts +++ b/packages/nodes-base/nodes/Harvest/ProjectDescription.ts @@ -1,6 +1,10 @@ -import { INodeProperties } from 'n8n-workflow'; +import { + INodeProperties, +} from 'n8n-workflow'; -const resource = ['project']; +const resource = [ + 'project', +]; export const projectOperations = [ { @@ -48,7 +52,7 @@ export const projectOperations = [ export const projectFields = [ /* -------------------------------------------------------------------------- */ - /* projects:getAll */ + /* projects:getAll */ /* -------------------------------------------------------------------------- */ { @@ -138,7 +142,7 @@ export const projectFields = [ }, /* -------------------------------------------------------------------------- */ - /* project:get */ + /* project:get */ /* -------------------------------------------------------------------------- */ { displayName: 'Project Id', @@ -158,7 +162,7 @@ export const projectFields = [ }, /* -------------------------------------------------------------------------- */ - /* project:delete */ + /* project:delete */ /* -------------------------------------------------------------------------- */ { displayName: 'Project Id', @@ -178,7 +182,7 @@ export const projectFields = [ }, /* -------------------------------------------------------------------------- */ - /* project:create */ + /* project:create */ /* -------------------------------------------------------------------------- */ { displayName: 'Name', @@ -399,7 +403,7 @@ export const projectFields = [ }, /* -------------------------------------------------------------------------- */ - /* project:update */ + /* project:update */ /* -------------------------------------------------------------------------- */ { displayName: 'Project Id', diff --git a/packages/nodes-base/nodes/Harvest/TaskDescription.ts b/packages/nodes-base/nodes/Harvest/TaskDescription.ts index a4926d70d1..90fc8d9c66 100644 --- a/packages/nodes-base/nodes/Harvest/TaskDescription.ts +++ b/packages/nodes-base/nodes/Harvest/TaskDescription.ts @@ -1,5 +1,11 @@ -import { INodeProperties } from 'n8n-workflow'; -const resource = ['task']; +import { + INodeProperties +} from 'n8n-workflow'; + +const resource = [ + 'task', +]; + export const taskOperations = [ { displayName: 'Operation', @@ -46,7 +52,7 @@ export const taskOperations = [ export const taskFields = [ /* -------------------------------------------------------------------------- */ - /* task:getAll */ + /* task:getAll */ /* -------------------------------------------------------------------------- */ { displayName: 'Return All', @@ -128,7 +134,7 @@ export const taskFields = [ }, /* -------------------------------------------------------------------------- */ - /* task:get */ + /* task:get */ /* -------------------------------------------------------------------------- */ { displayName: 'Task Id', @@ -148,7 +154,7 @@ export const taskFields = [ }, /* -------------------------------------------------------------------------- */ - /* task:delete */ + /* task:delete */ /* -------------------------------------------------------------------------- */ { displayName: 'Task Id', @@ -164,11 +170,11 @@ export const taskFields = [ 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', @@ -205,14 +211,14 @@ export const taskFields = [ displayName: 'Billable By Default', name: 'billable_by_default', type: 'boolean', - default: '', + default: true, description: 'Used in determining whether default tasks should be marked billable when creating a new project. Defaults to true.', }, { displayName: 'Default Hourly Rate', name: 'default_hourly_rate', - type: 'string', - default: '0', + type: 'number', + default: 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', name: 'updateFields', @@ -260,8 +282,8 @@ export const taskFields = [ { displayName: 'Default Hourly Rate', name: 'default_hourly_rate', - type: 'string', - default: '0', + type: 'number', + default: 0, description: 'The default hourly rate to use for this task when it is added to a project. Defaults to 0.', }, { diff --git a/packages/nodes-base/nodes/Harvest/TimeEntryDescription.ts b/packages/nodes-base/nodes/Harvest/TimeEntryDescription.ts index b4c40e8ce9..10bcca58fc 100644 --- a/packages/nodes-base/nodes/Harvest/TimeEntryDescription.ts +++ b/packages/nodes-base/nodes/Harvest/TimeEntryDescription.ts @@ -1,5 +1,11 @@ -import { INodeProperties } from 'n8n-workflow'; -export const resource = ['timeEntry']; +import { + INodeProperties, +} from 'n8n-workflow'; + +export const resource = [ + 'timeEntry', +]; + export const timeEntryOperations = [ { displayName: 'Operation', diff --git a/packages/nodes-base/nodes/Harvest/UserDescription.ts b/packages/nodes-base/nodes/Harvest/UserDescription.ts index 0254825b14..9e58123b34 100644 --- a/packages/nodes-base/nodes/Harvest/UserDescription.ts +++ b/packages/nodes-base/nodes/Harvest/UserDescription.ts @@ -1,6 +1,10 @@ -import { INodeProperties } from 'n8n-workflow'; +import { + INodeProperties, +} from 'n8n-workflow'; -const resource = ['user']; +const resource = [ + 'user', +]; export const userOperations = [ { @@ -54,7 +58,7 @@ export const userOperations = [ export const userFields = [ /* -------------------------------------------------------------------------- */ - /* user:getAll */ + /* user:getAll */ /* -------------------------------------------------------------------------- */ { @@ -137,7 +141,7 @@ export const userFields = [ }, /* -------------------------------------------------------------------------- */ - /* user:get */ + /* user:get */ /* -------------------------------------------------------------------------- */ { displayName: 'User Id', @@ -157,7 +161,7 @@ export const userFields = [ }, /* -------------------------------------------------------------------------- */ - /* user:delete */ + /* user:delete */ /* -------------------------------------------------------------------------- */ { displayName: 'User Id', @@ -177,7 +181,7 @@ export const userFields = [ }, /* -------------------------------------------------------------------------- */ - /* user:create */ + /* user:create */ /* -------------------------------------------------------------------------- */ { displayName: 'First Name', @@ -344,7 +348,7 @@ export const userFields = [ /* -------------------------------------------------------------------------- */ - /* user:update */ + /* user:update */ /* -------------------------------------------------------------------------- */ { displayName: 'Time Entry Id',