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 = [
{ {

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 = [
{ {

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 = [
{ {

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 = [
{ {

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 = [
{ {

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 = [
{ {

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',
@ -164,7 +170,7 @@ 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.',
}, },
/* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */
@ -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.',
}, },
{ {
@ -234,6 +240,22 @@ 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 = [
{ {