From cc302b7508ab2e9431d9c3c7a0dd33928cdab251 Mon Sep 17 00:00:00 2001 From: trojanh Date: Fri, 31 Jan 2020 19:36:10 +0530 Subject: [PATCH] Add task create and update --- .../nodes/Harvest/ClientDescription.ts | 8 +- .../nodes-base/nodes/Harvest/Harvest.node.ts | 32 +- .../nodes/Harvest/TaskDescription.ts | 364 ++++++++++++------ .../nodes/Harvest/UserDescription.ts | 296 +++++++------- 4 files changed, 430 insertions(+), 270 deletions(-) diff --git a/packages/nodes-base/nodes/Harvest/ClientDescription.ts b/packages/nodes-base/nodes/Harvest/ClientDescription.ts index 565cbf0635..532d3a67a2 100644 --- a/packages/nodes-base/nodes/Harvest/ClientDescription.ts +++ b/packages/nodes-base/nodes/Harvest/ClientDescription.ts @@ -9,7 +9,7 @@ export const clientOperations = [ type: 'options', displayOptions: { show: { - resource + resource, }, }, options: [ @@ -47,7 +47,7 @@ export const clientFields = [ type: 'boolean', displayOptions: { show: { - resource + resource, operation: [ 'getAll', ], @@ -62,7 +62,7 @@ export const clientFields = [ type: 'number', displayOptions: { show: { - resource + resource, operation: [ 'getAll', ], @@ -86,7 +86,7 @@ export const clientFields = [ default: {}, displayOptions: { show: { - resource + resource, operation: [ 'getAll', ], diff --git a/packages/nodes-base/nodes/Harvest/Harvest.node.ts b/packages/nodes-base/nodes/Harvest/Harvest.node.ts index 2cd1b0c6fe..b8a54c6167 100644 --- a/packages/nodes-base/nodes/Harvest/Harvest.node.ts +++ b/packages/nodes-base/nodes/Harvest/Harvest.node.ts @@ -546,7 +546,37 @@ export class Harvest implements INodeType { const responseData: IDataObject[] = await getAllResource.call(this, resource, i); returnData.push.apply(returnData, responseData); - } else if (operation === 'delete') { + } else if (operation === 'create') { + // ---------------------------------- + // create + // ---------------------------------- + + requestMethod = 'POST'; + endpoint = resource; + + 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') { + // ---------------------------------- + // createByDuration + // ---------------------------------- + + requestMethod = 'POST'; + endpoint = resource; + + 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/TaskDescription.ts b/packages/nodes-base/nodes/Harvest/TaskDescription.ts index feb404d8b5..2f37353647 100644 --- a/packages/nodes-base/nodes/Harvest/TaskDescription.ts +++ b/packages/nodes-base/nodes/Harvest/TaskDescription.ts @@ -1,5 +1,5 @@ import { INodeProperties } from "n8n-workflow"; -const resource = [ 'tasks' ]; +const resource = ['tasks']; export const taskOperations = [ { displayName: 'Operation', @@ -21,6 +21,16 @@ export const taskOperations = [ value: 'getAll', description: 'Get data of all tasks', }, + { + name: 'Create', + value: 'create', + description: `Create a task`, + }, + { + name: 'Update', + value: 'update', + description: `Update a task`, + }, { name: 'Delete', value: 'delete', @@ -35,128 +45,248 @@ export const taskOperations = [ export const taskFields = [ -/* -------------------------------------------------------------------------- */ -/* task:getAll */ -/* -------------------------------------------------------------------------- */ + /* -------------------------------------------------------------------------- */ + /* task:getAll */ + /* -------------------------------------------------------------------------- */ -{ - displayName: 'Return All', - name: 'returnAll', - type: 'boolean', - displayOptions: { - show: { - resource, - operation: [ - 'getAll', - ], - }, - }, - default: false, - description: 'Returns a list of your tasks.', -}, -{ - displayName: 'Limit', - name: 'limit', - type: 'number', - displayOptions: { - show: { - resource, - operation: [ - 'getAll', - ], - returnAll: [ - false, - ], - }, - }, - typeOptions: { - minValue: 1, - maxValue: 100, - }, - default: 100, - description: 'How many results to return.', -}, -{ - displayName: 'Filters', - name: 'filters', - type: 'collection', - placeholder: 'Add Filter', - default: {}, - displayOptions: { - show: { - resource, - operation: [ - 'getAll', - ], - }, - }, - options: [ - { - displayName: 'Is Active', - name: 'is_active', - type: 'boolean', - default: true, - description: 'Pass true to only return active tasks and false to return inactive tasks.', - }, - { - displayName: 'Updated Since', - name: 'updated_since', - type: 'dateTime', - default: '', - description: 'Only return tasks belonging to the task with the given ID.', - }, - { - displayName: 'Page', - name: 'page', - type: 'number', - typeOptions: { - minValue: 1, + { + displayName: 'Return All', + name: 'returnAll', + type: 'boolean', + displayOptions: { + show: { + resource, + operation: [ + 'getAll', + ], }, - default: 1, - description: 'The page number to use in pagination.', - } - ] -}, - -/* -------------------------------------------------------------------------- */ -/* task:get */ -/* -------------------------------------------------------------------------- */ -{ - displayName: 'Task Id', - name: 'id', - type: 'string', - default: '', - required: true, - displayOptions: { - show: { - operation: [ - 'get', - ], - resource, }, + default: false, + description: 'Returns a list of your tasks.', }, - description: 'The ID of the task you are retrieving.', -}, - -/* -------------------------------------------------------------------------- */ -/* task:delete */ -/* -------------------------------------------------------------------------- */ -{ - displayName: 'Task Id', - name: 'id', - type: 'string', - default: '', - required: true, - displayOptions: { - show: { - operation: [ - 'delete', - ], - resource, + { + displayName: 'Limit', + name: 'limit', + type: 'number', + displayOptions: { + show: { + resource, + operation: [ + 'getAll', + ], + returnAll: [ + false, + ], + }, }, + typeOptions: { + minValue: 1, + maxValue: 100, + }, + default: 100, + description: 'How many results to return.', + }, + { + displayName: 'Filters', + name: 'filters', + type: 'collection', + placeholder: 'Add Filter', + default: {}, + displayOptions: { + show: { + resource, + operation: [ + 'getAll', + ], + }, + }, + options: [ + { + displayName: 'Is Active', + name: 'is_active', + type: 'boolean', + default: true, + description: 'Pass true to only return active tasks and false to return inactive tasks.', + }, + { + displayName: 'Updated Since', + name: 'updated_since', + type: 'dateTime', + default: '', + description: 'Only return tasks belonging to the task with the given ID.', + }, + { + displayName: 'Page', + name: 'page', + type: 'number', + typeOptions: { + minValue: 1, + }, + default: 1, + description: 'The page number to use in pagination.', + } + ] + }, + + /* -------------------------------------------------------------------------- */ + /* task:get */ + /* -------------------------------------------------------------------------- */ + { + displayName: 'Task Id', + name: 'id', + type: 'string', + default: '', + required: true, + displayOptions: { + show: { + operation: [ + 'get', + ], + resource, + }, + }, + description: 'The ID of the task you are retrieving.', + }, + + /* -------------------------------------------------------------------------- */ + /* task:delete */ + /* -------------------------------------------------------------------------- */ + { + displayName: 'Task Id', + name: 'id', + type: 'string', + default: '', + required: true, + displayOptions: { + show: { + operation: [ + 'delete', + ], + resource, + }, + }, + description: 'The ID of the task you wan to delete.', + }, + + /* -------------------------------------------------------------------------- */ + /* task:create */ + /* -------------------------------------------------------------------------- */ + { + displayName: 'Name', + name: 'name', + type: 'string', + displayOptions: { + show: { + operation: [ + 'create', + ], + resource, + }, + }, + default: '', + required: true, + description: 'The name of the task.', + }, + { + displayName: 'Additional Fields', + name: 'additionalFields', + type: 'collection', + placeholder: 'Add Field', + displayOptions: { + show: { + operation: [ + 'create', + ], + resource, + }, + }, + default: {}, + options: [ + { + displayName: 'Billable By Default', + name: 'billable_by_default', + type: 'boolean', + default: '', + 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', + description: 'The default hourly rate to use for this task when it is added to a project. Defaults to 0.' + }, + { + displayName: 'Is Default', + name: 'is_default', + type: 'boolean', + default: false, + description: 'Whether this task should be automatically added to future projects. Defaults to false.' + }, + { + displayName: 'Is Active', + name: 'is_active', + type: 'boolean', + default: true, + description: 'Whether this task is active or archived. Defaults to true' + }, + ], + }, + /* -------------------------------------------------------------------------- */ + /* task:update */ + /* -------------------------------------------------------------------------- */ + { + displayName: 'Update Fields', + name: 'updateFields', + type: 'collection', + placeholder: 'Update Field', + displayOptions: { + show: { + operation: [ + 'update', + ], + resource, + }, + }, + default: {}, + options: [ + { + displayName: 'Name', + name: 'name', + type: 'string', + default: '', + description: 'Name of the task.' + }, + { + displayName: 'Billable By Default', + name: 'billable_by_default', + type: 'boolean', + default: '', + 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', + description: 'The default hourly rate to use for this task when it is added to a project. Defaults to 0.' + }, + { + displayName: 'Is Default', + name: 'is_default', + type: 'boolean', + default: false, + description: 'Whether this task should be automatically added to future projects. Defaults to false.' + }, + { + displayName: 'Is Active', + name: 'is_active', + type: 'boolean', + default: true, + description: 'Whether this task is active or archived. Defaults to true' + } + ], }, - description: 'The ID of the task you wan to delete.', -}, ] as INodeProperties[]; diff --git a/packages/nodes-base/nodes/Harvest/UserDescription.ts b/packages/nodes-base/nodes/Harvest/UserDescription.ts index 2c8023ac21..f0760daf45 100644 --- a/packages/nodes-base/nodes/Harvest/UserDescription.ts +++ b/packages/nodes-base/nodes/Harvest/UserDescription.ts @@ -175,10 +175,10 @@ export const userFields = [ description: 'The ID of the user you want to delete.', }, -/* -------------------------------------------------------------------------- */ -/* user:create */ -/* -------------------------------------------------------------------------- */ -{ + /* -------------------------------------------------------------------------- */ + /* user:create */ + /* -------------------------------------------------------------------------- */ + { displayName: 'First Name', name: 'first_name', type: 'string', @@ -336,153 +336,153 @@ export const userFields = [ }, -/* -------------------------------------------------------------------------- */ -/* user:update */ -/* -------------------------------------------------------------------------- */ -{ - displayName: 'Time Entry Id', - name: 'id', - type: 'string', - default: '', - required: true, - displayOptions: { - show: { - operation: [ - 'update', - ], - resource, + /* -------------------------------------------------------------------------- */ + /* user:update */ + /* -------------------------------------------------------------------------- */ + { + displayName: 'Time Entry Id', + name: 'id', + type: 'string', + default: '', + required: true, + displayOptions: { + show: { + operation: [ + 'update', + ], + resource, + }, }, + description: 'The ID of the time entry to update.', }, - description: 'The ID of the time entry to update.', -}, -{ - displayName: 'Update Fields', - name: 'updateFields', - type: 'collection', - placeholder: 'Add Field', - displayOptions: { - show: { - operation: [ - 'update', - ], - resource + { + displayName: 'Update Fields', + name: 'updateFields', + type: 'collection', + placeholder: 'Add Field', + displayOptions: { + show: { + operation: [ + 'update', + ], + resource + }, }, + default: {}, + options: [ + { + displayName: 'First Name', + name: 'first_name', + type: 'string', + default: '', + description: 'The user first name' + }, + { + displayName: 'Last Name', + name: 'last_name', + type: 'string', + default: '', + description: 'The user last name' + }, + { + displayName: 'Email', + name: 'email', + type: 'string', + default: '', + description: 'The user email' + }, + { + displayName: 'Timezone', + name: 'timezone', + type: 'string', + default: '', + description: 'The user’s timezone. Defaults to the company’s timezone. See a list of supported time zones.' + }, + { + displayName: 'Has Access To All Future Projects', + name: 'has_access_to_all_future_projects', + type: 'string', + default: '', + description: 'Whether the user should be automatically added to future projects. Defaults to false.' + }, + { + displayName: 'Is Contractor', + name: 'is_contractor', + type: 'string', + default: '', + description: 'Whether the user is a contractor or an employee. Defaults to false.' + }, + { + displayName: 'Is Admin', + name: 'is_admin', + type: 'string', + default: '', + description: 'Whether the user has Admin permissions. Defaults to false.' + }, + { + displayName: 'Is Project Manager', + name: 'is_project_manager', + type: 'string', + default: '', + description: 'Whether the user has Project Manager permissions. Defaults to false.' + }, + { + displayName: 'Can See Rates', + name: 'can_see_rates', + type: 'string', + default: '', + description: 'Whether the user can see billable rates on projects. Only applicable to Project Managers. Defaults to false.' + }, + { + displayName: 'Can Create Projects', + name: 'can_create_projects', + type: 'string', + default: '', + description: 'Whether the user can create projects. Only applicable to Project Managers. Defaults to false.' + }, + { + displayName: 'Can Create Invoices', + name: 'can_create_invoices', + type: 'string', + default: '', + description: 'Whether the user can create invoices. Only applicable to Project Managers. Defaults to false.' + }, + { + displayName: 'Is Active', + name: 'is_active', + type: 'string', + default: '', + description: 'Whether the user is active or archived. Defaults to true.' + }, + { + displayName: 'Weekly Capacity', + name: 'weekly_capacity', + type: 'string', + default: '', + description: 'The number of hours per week this person is available to work in seconds. Defaults to 126000 seconds (35 hours).' + }, + { + displayName: 'Default Hourly Rate', + name: 'default_hourly_rate', + type: 'string', + default: '', + description: 'The billable rate to use for this user when they are added to a project. Defaults to 0.' + }, + { + displayName: 'Cost Rate', + name: 'cost_rate', + type: 'string', + default: '', + description: 'The cost rate to use for this user when calculating a project’s costs vs billable amount. Defaults to 0.' + }, + { + displayName: 'Roles', + name: 'roles', + type: 'string', + default: '', + description: 'The role names assigned to this person.' + }, + ], }, - default: {}, - options: [ - { - displayName: 'First Name', - name: 'first_name', - type: 'string', - default: '', - description: 'The user first name' - }, - { - displayName: 'Last Name', - name: 'last_name', - type: 'string', - default: '', - description: 'The user last name' - }, - { - displayName: 'Email', - name: 'email', - type: 'string', - default: '', - description: 'The user email' - }, - { - displayName: 'Timezone', - name: 'timezone', - type: 'string', - default: '', - description: 'The user’s timezone. Defaults to the company’s timezone. See a list of supported time zones.' - }, - { - displayName: 'Has Access To All Future Projects', - name: 'has_access_to_all_future_projects', - type: 'string', - default: '', - description: 'Whether the user should be automatically added to future projects. Defaults to false.' - }, - { - displayName: 'Is Contractor', - name: 'is_contractor', - type: 'string', - default: '', - description: 'Whether the user is a contractor or an employee. Defaults to false.' - }, - { - displayName: 'Is Admin', - name: 'is_admin', - type: 'string', - default: '', - description: 'Whether the user has Admin permissions. Defaults to false.' - }, - { - displayName: 'Is Project Manager', - name: 'is_project_manager', - type: 'string', - default: '', - description: 'Whether the user has Project Manager permissions. Defaults to false.' - }, - { - displayName: 'Can See Rates', - name: 'can_see_rates', - type: 'string', - default: '', - description: 'Whether the user can see billable rates on projects. Only applicable to Project Managers. Defaults to false.' - }, - { - displayName: 'Can Create Projects', - name: 'can_create_projects', - type: 'string', - default: '', - description: 'Whether the user can create projects. Only applicable to Project Managers. Defaults to false.' - }, - { - displayName: 'Can Create Invoices', - name: 'can_create_invoices', - type: 'string', - default: '', - description: 'Whether the user can create invoices. Only applicable to Project Managers. Defaults to false.' - }, - { - displayName: 'Is Active', - name: 'is_active', - type: 'string', - default: '', - description: 'Whether the user is active or archived. Defaults to true.' - }, - { - displayName: 'Weekly Capacity', - name: 'weekly_capacity', - type: 'string', - default: '', - description: 'The number of hours per week this person is available to work in seconds. Defaults to 126000 seconds (35 hours).' - }, - { - displayName: 'Default Hourly Rate', - name: 'default_hourly_rate', - type: 'string', - default: '', - description: 'The billable rate to use for this user when they are added to a project. Defaults to 0.' - }, - { - displayName: 'Cost Rate', - name: 'cost_rate', - type: 'string', - default: '', - description: 'The cost rate to use for this user when calculating a project’s costs vs billable amount. Defaults to 0.' - }, - { - displayName: 'Roles', - name: 'roles', - type: 'string', - default: '', - description: 'The role names assigned to this person.' - }, - ], -}, ] as INodeProperties[];