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',
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',
],

View file

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

View file

@ -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,11 +45,11 @@ export const taskOperations = [
export const taskFields = [
/* -------------------------------------------------------------------------- */
/* task:getAll */
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
/* task:getAll */
/* -------------------------------------------------------------------------- */
{
{
displayName: 'Return All',
name: 'returnAll',
type: 'boolean',
@ -53,8 +63,8 @@ export const taskFields = [
},
default: false,
description: 'Returns a list of your tasks.',
},
{
},
{
displayName: 'Limit',
name: 'limit',
type: 'number',
@ -75,8 +85,8 @@ export const taskFields = [
},
default: 100,
description: 'How many results to return.',
},
{
},
{
displayName: 'Filters',
name: 'filters',
type: 'collection',
@ -116,12 +126,12 @@ export const taskFields = [
description: 'The page number to use in pagination.',
}
]
},
},
/* -------------------------------------------------------------------------- */
/* task:get */
/* -------------------------------------------------------------------------- */
{
/* -------------------------------------------------------------------------- */
/* task:get */
/* -------------------------------------------------------------------------- */
{
displayName: 'Task Id',
name: 'id',
type: 'string',
@ -136,12 +146,12 @@ export const taskFields = [
},
},
description: 'The ID of the task you are retrieving.',
},
},
/* -------------------------------------------------------------------------- */
/* task:delete */
/* -------------------------------------------------------------------------- */
{
/* -------------------------------------------------------------------------- */
/* task:delete */
/* -------------------------------------------------------------------------- */
{
displayName: 'Task Id',
name: 'id',
type: 'string',
@ -156,7 +166,127 @@ export const taskFields = [
},
},
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[];

View file

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