Add task create and update

This commit is contained in:
trojanh 2020-01-31 19:36:10 +05:30
parent 1759f6ce98
commit cc302b7508
4 changed files with 430 additions and 270 deletions

View file

@ -9,7 +9,7 @@ export const clientOperations = [
type: 'options', type: 'options',
displayOptions: { displayOptions: {
show: { show: {
resource resource,
}, },
}, },
options: [ options: [
@ -47,7 +47,7 @@ export const clientFields = [
type: 'boolean', type: 'boolean',
displayOptions: { displayOptions: {
show: { show: {
resource resource,
operation: [ operation: [
'getAll', 'getAll',
], ],
@ -62,7 +62,7 @@ export const clientFields = [
type: 'number', type: 'number',
displayOptions: { displayOptions: {
show: { show: {
resource resource,
operation: [ operation: [
'getAll', 'getAll',
], ],
@ -86,7 +86,7 @@ export const clientFields = [
default: {}, default: {},
displayOptions: { displayOptions: {
show: { show: {
resource resource,
operation: [ operation: [
'getAll', 'getAll',
], ],

View file

@ -546,6 +546,36 @@ export class Harvest implements INodeType {
const responseData: IDataObject[] = await getAllResource.call(this, resource, i); const responseData: IDataObject[] = await getAllResource.call(this, resource, i);
returnData.push.apply(returnData, responseData); returnData.push.apply(returnData, responseData);
} 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') { } else if (operation === 'delete') {
// ---------------------------------- // ----------------------------------
// delete // delete

View file

@ -1,5 +1,5 @@
import { INodeProperties } from "n8n-workflow"; import { INodeProperties } from "n8n-workflow";
const resource = [ 'tasks' ]; const resource = ['tasks'];
export const taskOperations = [ export const taskOperations = [
{ {
displayName: 'Operation', displayName: 'Operation',
@ -21,6 +21,16 @@ export const taskOperations = [
value: 'getAll', value: 'getAll',
description: 'Get data of all tasks', description: 'Get data of all tasks',
}, },
{
name: 'Create',
value: 'create',
description: `Create a task`,
},
{
name: 'Update',
value: 'update',
description: `Update a task`,
},
{ {
name: 'Delete', name: 'Delete',
value: 'delete', value: 'delete',
@ -35,11 +45,11 @@ export const taskOperations = [
export const taskFields = [ export const taskFields = [
/* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */
/* task:getAll */ /* task:getAll */
/* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */
{ {
displayName: 'Return All', displayName: 'Return All',
name: 'returnAll', name: 'returnAll',
type: 'boolean', type: 'boolean',
@ -53,8 +63,8 @@ export const taskFields = [
}, },
default: false, default: false,
description: 'Returns a list of your tasks.', description: 'Returns a list of your tasks.',
}, },
{ {
displayName: 'Limit', displayName: 'Limit',
name: 'limit', name: 'limit',
type: 'number', type: 'number',
@ -75,8 +85,8 @@ export const taskFields = [
}, },
default: 100, default: 100,
description: 'How many results to return.', description: 'How many results to return.',
}, },
{ {
displayName: 'Filters', displayName: 'Filters',
name: 'filters', name: 'filters',
type: 'collection', type: 'collection',
@ -116,12 +126,12 @@ export const taskFields = [
description: 'The page number to use in pagination.', description: 'The page number to use in pagination.',
} }
] ]
}, },
/* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */
/* task:get */ /* task:get */
/* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */
{ {
displayName: 'Task Id', displayName: 'Task Id',
name: 'id', name: 'id',
type: 'string', type: 'string',
@ -136,12 +146,12 @@ export const taskFields = [
}, },
}, },
description: 'The ID of the task you are retrieving.', description: 'The ID of the task you are retrieving.',
}, },
/* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */
/* task:delete */ /* task:delete */
/* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */
{ {
displayName: 'Task Id', displayName: 'Task Id',
name: 'id', name: 'id',
type: 'string', type: 'string',
@ -156,7 +166,127 @@ export const taskFields = [
}, },
}, },
description: 'The ID of the task you wan to delete.', 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'
}
],
},
] as INodeProperties[]; ] as INodeProperties[];

View file

@ -175,10 +175,10 @@ export const userFields = [
description: 'The ID of the user you want to delete.', description: 'The ID of the user you want to delete.',
}, },
/* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */
/* user:create */ /* user:create */
/* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */
{ {
displayName: 'First Name', displayName: 'First Name',
name: 'first_name', name: 'first_name',
type: 'string', type: 'string',
@ -336,10 +336,10 @@ export const userFields = [
}, },
/* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */
/* user:update */ /* user:update */
/* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */
{ {
displayName: 'Time Entry Id', displayName: 'Time Entry Id',
name: 'id', name: 'id',
type: 'string', type: 'string',
@ -354,8 +354,8 @@ export const userFields = [
}, },
}, },
description: 'The ID of the time entry to update.', description: 'The ID of the time entry to update.',
}, },
{ {
displayName: 'Update Fields', displayName: 'Update Fields',
name: 'updateFields', name: 'updateFields',
type: 'collection', type: 'collection',
@ -483,6 +483,6 @@ export const userFields = [
description: 'The role names assigned to this person.</td>' description: 'The role names assigned to this person.</td>'
}, },
], ],
}, },
] as INodeProperties[]; ] as INodeProperties[];