From 1759f6ce981e09b36765b932ba99abefe682149d Mon Sep 17 00:00:00 2001 From: trojanh Date: Fri, 31 Jan 2020 19:13:40 +0530 Subject: [PATCH] Refactor reource names to match endpoint --- .../nodes/Harvest/ClientDescription.ts | 26 ++----- .../nodes/Harvest/CompanyDescription.ts | 6 +- .../nodes/Harvest/ContactDescription.ts | 26 ++----- .../nodes/Harvest/EstimateDescription.ts | 26 ++----- .../nodes/Harvest/ExpenseDescription.ts | 26 ++----- .../nodes-base/nodes/Harvest/Harvest.node.ts | 78 +++++++++---------- .../nodes/Harvest/InvoiceDescription.ts | 26 ++----- .../nodes/Harvest/ProjectDescription.ts | 26 ++----- .../nodes/Harvest/TaskDescription.ts | 26 ++----- 9 files changed, 97 insertions(+), 169 deletions(-) diff --git a/packages/nodes-base/nodes/Harvest/ClientDescription.ts b/packages/nodes-base/nodes/Harvest/ClientDescription.ts index fe769b5ebf..565cbf0635 100644 --- a/packages/nodes-base/nodes/Harvest/ClientDescription.ts +++ b/packages/nodes-base/nodes/Harvest/ClientDescription.ts @@ -1,5 +1,7 @@ import { INodeProperties } from "n8n-workflow"; +const resource = [ 'clients' ]; + export const clientOperations = [ { displayName: 'Operation', @@ -7,9 +9,7 @@ export const clientOperations = [ type: 'options', displayOptions: { show: { - resource: [ - 'client', - ], + resource }, }, options: [ @@ -47,9 +47,7 @@ export const clientFields = [ type: 'boolean', displayOptions: { show: { - resource: [ - 'client', - ], + resource operation: [ 'getAll', ], @@ -64,9 +62,7 @@ export const clientFields = [ type: 'number', displayOptions: { show: { - resource: [ - 'client', - ], + resource operation: [ 'getAll', ], @@ -90,9 +86,7 @@ export const clientFields = [ default: {}, displayOptions: { show: { - resource: [ - 'client', - ], + resource operation: [ 'getAll', ], @@ -130,9 +124,7 @@ export const clientFields = [ operation: [ 'get', ], - resource: [ - 'client', - ], + resource }, }, description: 'The ID of the client you are retrieving.', @@ -152,9 +144,7 @@ export const clientFields = [ operation: [ 'delete', ], - resource: [ - 'client', - ], + resource }, }, description: 'The ID of the client you want to delete.', diff --git a/packages/nodes-base/nodes/Harvest/CompanyDescription.ts b/packages/nodes-base/nodes/Harvest/CompanyDescription.ts index 26303b7eb3..8de3c255cc 100644 --- a/packages/nodes-base/nodes/Harvest/CompanyDescription.ts +++ b/packages/nodes-base/nodes/Harvest/CompanyDescription.ts @@ -1,5 +1,7 @@ import { INodeProperties } from "n8n-workflow"; +const resource = [ 'companies' ]; + export const companyOperations = [ { displayName: 'Operation', @@ -7,9 +9,7 @@ export const companyOperations = [ type: 'options', displayOptions: { show: { - resource: [ - 'company', - ], + resource, }, }, options: [ diff --git a/packages/nodes-base/nodes/Harvest/ContactDescription.ts b/packages/nodes-base/nodes/Harvest/ContactDescription.ts index 1c1d645fe7..66dd0386e3 100644 --- a/packages/nodes-base/nodes/Harvest/ContactDescription.ts +++ b/packages/nodes-base/nodes/Harvest/ContactDescription.ts @@ -1,5 +1,7 @@ import { INodeProperties } from "n8n-workflow"; +const resource = [ 'contacts' ]; + export const contactOperations = [ { displayName: 'Operation', @@ -7,9 +9,7 @@ export const contactOperations = [ type: 'options', displayOptions: { show: { - resource: [ - 'contact', - ], + resource, }, }, options: [ @@ -47,9 +47,7 @@ export const contactFields = [ type: 'boolean', displayOptions: { show: { - resource: [ - 'contact', - ], + resource, operation: [ 'getAll', ], @@ -64,9 +62,7 @@ export const contactFields = [ type: 'number', displayOptions: { show: { - resource: [ - 'contact', - ], + resource, operation: [ 'getAll', ], @@ -90,9 +86,7 @@ export const contactFields = [ default: {}, displayOptions: { show: { - resource: [ - 'contact', - ], + resource, operation: [ 'getAll', ], @@ -130,9 +124,7 @@ export const contactFields = [ operation: [ 'get', ], - resource: [ - 'contact', - ], + resource, }, }, description: 'The ID of the contact you are retrieving.', @@ -152,9 +144,7 @@ export const contactFields = [ operation: [ 'delete', ], - resource: [ - 'contact', - ], + resource, }, }, description: 'The ID of the contact you want to delete.', diff --git a/packages/nodes-base/nodes/Harvest/EstimateDescription.ts b/packages/nodes-base/nodes/Harvest/EstimateDescription.ts index cc0e3e02a3..4216ab0db7 100644 --- a/packages/nodes-base/nodes/Harvest/EstimateDescription.ts +++ b/packages/nodes-base/nodes/Harvest/EstimateDescription.ts @@ -1,5 +1,7 @@ import { INodeProperties } from "n8n-workflow"; +const resource = [ 'estimates' ]; + export const estimateOperations = [ { displayName: 'Operation', @@ -7,9 +9,7 @@ export const estimateOperations = [ type: 'options', displayOptions: { show: { - resource: [ - 'estimate', - ], + resource, }, }, options: [ @@ -47,9 +47,7 @@ export const estimateFields = [ type: 'boolean', displayOptions: { show: { - resource: [ - 'estimate', - ], + resource, operation: [ 'getAll', ], @@ -64,9 +62,7 @@ export const estimateFields = [ type: 'number', displayOptions: { show: { - resource: [ - 'estimate', - ], + resource, operation: [ 'getAll', ], @@ -90,9 +86,7 @@ export const estimateFields = [ default: {}, displayOptions: { show: { - resource: [ - 'estimate', - ], + resource, operation: [ 'getAll', ], @@ -161,9 +155,7 @@ export const estimateFields = [ operation: [ 'get', ], - resource: [ - 'estimate', - ], + resource, }, }, description: 'The ID of the estimate you are retrieving.', @@ -183,9 +175,7 @@ export const estimateFields = [ operation: [ 'delete', ], - resource: [ - 'estimate', - ], + resource, }, }, description: 'The ID of the estimate want to delete.', diff --git a/packages/nodes-base/nodes/Harvest/ExpenseDescription.ts b/packages/nodes-base/nodes/Harvest/ExpenseDescription.ts index 96626056ac..ff1613d62e 100644 --- a/packages/nodes-base/nodes/Harvest/ExpenseDescription.ts +++ b/packages/nodes-base/nodes/Harvest/ExpenseDescription.ts @@ -1,5 +1,7 @@ import { INodeProperties } from "n8n-workflow"; +const resource = [ 'invoices' ]; + export const expenseOperations = [ { displayName: 'Operation', @@ -7,9 +9,7 @@ export const expenseOperations = [ type: 'options', displayOptions: { show: { - resource: [ - 'expense', - ], + resource, }, }, options: [ @@ -47,9 +47,7 @@ export const expenseFields = [ type: 'boolean', displayOptions: { show: { - resource: [ - 'expense', - ], + resource, operation: [ 'getAll', ], @@ -64,9 +62,7 @@ export const expenseFields = [ type: 'number', displayOptions: { show: { - resource: [ - 'expense', - ], + resource, operation: [ 'getAll', ], @@ -90,9 +86,7 @@ export const expenseFields = [ default: {}, displayOptions: { show: { - resource: [ - 'expense', - ], + resource, operation: [ 'getAll', ], @@ -175,9 +169,7 @@ export const expenseFields = [ operation: [ 'get', ], - resource: [ - 'expense', - ], + resource, }, }, description: 'The ID of the expense you are retrieving.', @@ -197,9 +189,7 @@ export const expenseFields = [ operation: [ 'delete', ], - resource: [ - 'expense', - ], + resource, }, }, description: 'The ID of the expense you want to delete.', diff --git a/packages/nodes-base/nodes/Harvest/Harvest.node.ts b/packages/nodes-base/nodes/Harvest/Harvest.node.ts index 260000e6f4..2cd1b0c6fe 100644 --- a/packages/nodes-base/nodes/Harvest/Harvest.node.ts +++ b/packages/nodes-base/nodes/Harvest/Harvest.node.ts @@ -75,35 +75,35 @@ export class Harvest implements INodeType { { name: 'Client', - value: 'client', + value: 'clients', }, { name: 'Company', - value: 'company', + value: 'companies', }, { name: 'Contact', - value: 'contact', + value: 'contacts', }, { name: 'Estimates', - value: 'estimate', + value: 'estimates', }, { name: 'Expense', - value: 'expense', + value: 'expenses', }, { name: 'Invoice', - value: 'invoice', + value: 'invoices', }, { name: 'Project', - value: 'project', + value: 'projects', }, { name: 'Task', - value: 'task', + value: 'tasks', }, { name: 'Time Entries', @@ -114,7 +114,7 @@ export class Harvest implements INodeType { value: 'users', }, ], - default: 'task', + default: 'tasks', description: 'The resource to operate on.', }, @@ -284,7 +284,7 @@ export class Harvest implements INodeType { throw new Error(`The operation "${operation}" is not known!`); } - } else if (resource === 'client') { + } else if (resource === 'clients') { if (operation === 'get') { // ---------------------------------- // get @@ -293,7 +293,7 @@ export class Harvest implements INodeType { requestMethod = 'GET'; const id = this.getNodeParameter('id', i) as string; - endpoint = `clients/${id}`; + endpoint = `${resource}/${id}`; const responseData = await harvestApiRequest.call(this, requestMethod, qs, endpoint); returnData.push(responseData); @@ -303,7 +303,7 @@ export class Harvest implements INodeType { // getAll // ---------------------------------- - const responseData: IDataObject[] = await getAllResource.call(this, 'clients', i); + const responseData: IDataObject[] = await getAllResource.call(this, resource, i); returnData.push.apply(returnData, responseData); } else if (operation === 'delete') { @@ -313,14 +313,14 @@ export class Harvest implements INodeType { requestMethod = 'DELETE'; const id = this.getNodeParameter('id', i) as string; - endpoint = `clients/${id}`; + endpoint = `${resource}/${id}`; const responseData = await harvestApiRequest.call(this, requestMethod, qs, endpoint); returnData.push(responseData); } else { throw new Error(`The resource "${resource}" is not known!`); } - } else if (resource === 'project') { + } else if (resource === 'projects') { if (operation === 'get') { // ---------------------------------- // get @@ -329,7 +329,7 @@ export class Harvest implements INodeType { requestMethod = 'GET'; const id = this.getNodeParameter('id', i) as string; - endpoint = `projects/${id}`; + endpoint = `${resource}/${id}`; const responseData = await harvestApiRequest.call(this, requestMethod, qs, endpoint); returnData.push(responseData); @@ -339,7 +339,7 @@ export class Harvest implements INodeType { // getAll // ---------------------------------- - const responseData: IDataObject[] = await getAllResource.call(this, 'projects', i); + const responseData: IDataObject[] = await getAllResource.call(this, resource, i); returnData.push.apply(returnData, responseData); } else if (operation === 'delete') { @@ -349,7 +349,7 @@ export class Harvest implements INodeType { requestMethod = 'DELETE'; const id = this.getNodeParameter('id', i) as string; - endpoint = `projects/${id}`; + endpoint = `${resource}/${id}`; const responseData = await harvestApiRequest.call(this, requestMethod, qs, endpoint); returnData.push(responseData); @@ -430,14 +430,14 @@ export class Harvest implements INodeType { requestMethod = 'DELETE'; const id = this.getNodeParameter('id', i) as string; - endpoint = `users/${id}`; + endpoint = `${resource}/${id}`; const responseData = await harvestApiRequest.call(this, requestMethod, qs, endpoint); returnData.push(responseData); } else { throw new Error(`The resource "${resource}" is not known!`); } - } else if (resource === 'contact') { + } else if (resource === 'contacts') { if (operation === 'get') { // ---------------------------------- // get @@ -446,7 +446,7 @@ export class Harvest implements INodeType { requestMethod = 'GET'; const id = this.getNodeParameter('id', i) as string; - endpoint = `contacts/${id}`; + endpoint = `${resource}/${id}`; const responseData = await harvestApiRequest.call(this, requestMethod, qs, endpoint); returnData.push(responseData); @@ -456,7 +456,7 @@ export class Harvest implements INodeType { // getAll // ---------------------------------- - const responseData: IDataObject[] = await getAllResource.call(this, 'contacts', i); + const responseData: IDataObject[] = await getAllResource.call(this, resource, i); returnData.push.apply(returnData, responseData); } else if (operation === 'delete') { @@ -466,14 +466,14 @@ export class Harvest implements INodeType { requestMethod = 'DELETE'; const id = this.getNodeParameter('id', i) as string; - endpoint = `contacts/${id}`; + endpoint = `${resource}/${id}`; const responseData = await harvestApiRequest.call(this, requestMethod, qs, endpoint); returnData.push(responseData); } else { throw new Error(`The resource "${resource}" is not known!`); } - } else if (resource === 'company') { + } else if (resource === 'companies') { if (operation === 'get') { // ---------------------------------- // get @@ -488,7 +488,7 @@ export class Harvest implements INodeType { } else { throw new Error(`The resource "${resource}" is not known!`); } - } else if (resource === 'task') { + } else if (resource === 'tasks') { if (operation === 'get') { // ---------------------------------- // get @@ -497,7 +497,7 @@ export class Harvest implements INodeType { requestMethod = 'GET'; const id = this.getNodeParameter('id', i) as string; - endpoint = `tasks/${id}`; + endpoint = `${resource}/${id}`; const responseData = await harvestApiRequest.call(this, requestMethod, qs, endpoint); returnData.push(responseData); @@ -507,7 +507,7 @@ export class Harvest implements INodeType { // getAll // ---------------------------------- - const responseData: IDataObject[] = await getAllResource.call(this, 'tasks', i); + const responseData: IDataObject[] = await getAllResource.call(this, resource, i); returnData.push.apply(returnData, responseData); } else if (operation === 'delete') { @@ -517,14 +517,14 @@ export class Harvest implements INodeType { requestMethod = 'DELETE'; const id = this.getNodeParameter('id', i) as string; - endpoint = `tasks/${id}`; + endpoint = `${resource}/${id}`; const responseData = await harvestApiRequest.call(this, requestMethod, qs, endpoint); returnData.push(responseData); } else { throw new Error(`The resource "${resource}" is not known!`); } - } else if (resource === 'invoice') { + } else if (resource === 'invoices') { if (operation === 'get') { // ---------------------------------- // get @@ -533,7 +533,7 @@ export class Harvest implements INodeType { requestMethod = 'GET'; const id = this.getNodeParameter('id', i) as string; - endpoint = `invoices/${id}`; + endpoint = `${resource}/${id}`; const responseData = await harvestApiRequest.call(this, requestMethod, qs, endpoint); returnData.push(responseData); @@ -543,7 +543,7 @@ export class Harvest implements INodeType { // getAll // ---------------------------------- - const responseData: IDataObject[] = await getAllResource.call(this, 'invoices', i); + const responseData: IDataObject[] = await getAllResource.call(this, resource, i); returnData.push.apply(returnData, responseData); } else if (operation === 'delete') { @@ -553,14 +553,14 @@ export class Harvest implements INodeType { requestMethod = 'DELETE'; const id = this.getNodeParameter('id', i) as string; - endpoint = `invoices/${id}`; + endpoint = `${resource}/${id}`; const responseData = await harvestApiRequest.call(this, requestMethod, qs, endpoint); returnData.push(responseData); } else { throw new Error(`The resource "${resource}" is not known!`); } - } else if (resource === 'expense') { + } else if (resource === 'expenses') { if (operation === 'get') { // ---------------------------------- // get @@ -569,7 +569,7 @@ export class Harvest implements INodeType { requestMethod = 'GET'; const id = this.getNodeParameter('id', i) as string; - endpoint = `expenses/${id}`; + endpoint = `${resource}/${id}`; const responseData = await harvestApiRequest.call(this, requestMethod, qs, endpoint); returnData.push(responseData); @@ -579,7 +579,7 @@ export class Harvest implements INodeType { // getAll // ---------------------------------- - const responseData: IDataObject[] = await getAllResource.call(this, 'expenses', i); + const responseData: IDataObject[] = await getAllResource.call(this, resource, i); returnData.push.apply(returnData, responseData); } else if (operation === 'delete') { @@ -589,14 +589,14 @@ export class Harvest implements INodeType { requestMethod = 'DELETE'; const id = this.getNodeParameter('id', i) as string; - endpoint = `expenses/${id}`; + endpoint = `${resource}/${id}`; const responseData = await harvestApiRequest.call(this, requestMethod, qs, endpoint); returnData.push(responseData); } else { throw new Error(`The resource "${resource}" is not known!`); } - } else if (resource === 'estimate') { + } else if (resource === 'estimates') { if (operation === 'get') { // ---------------------------------- // get @@ -605,7 +605,7 @@ export class Harvest implements INodeType { requestMethod = 'GET'; const id = this.getNodeParameter('id', i) as string; - endpoint = `estimates/${id}`; + endpoint = `${resource}/${id}`; const responseData = await harvestApiRequest.call(this, requestMethod, qs, endpoint); returnData.push(responseData); @@ -615,7 +615,7 @@ export class Harvest implements INodeType { // getAll // ---------------------------------- - const responseData: IDataObject[] = await getAllResource.call(this, 'estimates', i); + const responseData: IDataObject[] = await getAllResource.call(this, resource, i); returnData.push.apply(returnData, responseData); } else if (operation === 'delete') { @@ -625,7 +625,7 @@ export class Harvest implements INodeType { requestMethod = 'DELETE'; const id = this.getNodeParameter('id', i) as string; - endpoint = `estimates/${id}`; + endpoint = `${resource}/${id}`; const responseData = await harvestApiRequest.call(this, requestMethod, qs, endpoint); returnData.push(responseData); diff --git a/packages/nodes-base/nodes/Harvest/InvoiceDescription.ts b/packages/nodes-base/nodes/Harvest/InvoiceDescription.ts index fe19a8463e..8ec5814dff 100644 --- a/packages/nodes-base/nodes/Harvest/InvoiceDescription.ts +++ b/packages/nodes-base/nodes/Harvest/InvoiceDescription.ts @@ -1,5 +1,7 @@ import { INodeProperties } from "n8n-workflow"; +const resource = [ 'invoices' ]; + export const invoiceOperations = [ { displayName: 'Operation', @@ -7,9 +9,7 @@ export const invoiceOperations = [ type: 'options', displayOptions: { show: { - resource: [ - 'invoice', - ], + resource, }, }, options: [ @@ -47,9 +47,7 @@ export const invoiceFields = [ type: 'boolean', displayOptions: { show: { - resource: [ - 'invoice', - ], + resource, operation: [ 'getAll', ], @@ -64,9 +62,7 @@ export const invoiceFields = [ type: 'number', displayOptions: { show: { - resource: [ - 'invoice', - ], + resource, operation: [ 'getAll', ], @@ -90,9 +86,7 @@ export const invoiceFields = [ default: {}, displayOptions: { show: { - resource: [ - 'invoice', - ], + resource, operation: [ 'getAll', ], @@ -186,9 +180,7 @@ export const invoiceFields = [ operation: [ 'get', ], - resource: [ - 'invoice', - ], + resource, }, }, description: 'The ID of the invoice you are retrieving.', @@ -208,9 +200,7 @@ export const invoiceFields = [ operation: [ 'delete', ], - resource: [ - 'invoice', - ], + resource, }, }, description: 'The ID of the invoice want to delete.', diff --git a/packages/nodes-base/nodes/Harvest/ProjectDescription.ts b/packages/nodes-base/nodes/Harvest/ProjectDescription.ts index 7d039ccab9..c80c677247 100644 --- a/packages/nodes-base/nodes/Harvest/ProjectDescription.ts +++ b/packages/nodes-base/nodes/Harvest/ProjectDescription.ts @@ -1,5 +1,7 @@ import { INodeProperties } from "n8n-workflow"; +const resource = [ 'projects' ]; + export const projectOperations = [ { displayName: 'Operation', @@ -7,9 +9,7 @@ export const projectOperations = [ type: 'options', displayOptions: { show: { - resource: [ - 'project', - ], + resource, }, }, options: [ @@ -47,9 +47,7 @@ export const projectFields = [ type: 'boolean', displayOptions: { show: { - resource: [ - 'project', - ], + resource, operation: [ 'getAll', ], @@ -64,9 +62,7 @@ export const projectFields = [ type: 'number', displayOptions: { show: { - resource: [ - 'project', - ], + resource, operation: [ 'getAll', ], @@ -90,9 +86,7 @@ export const projectFields = [ default: {}, displayOptions: { show: { - resource: [ - 'project', - ], + resource, operation: [ 'getAll', ], @@ -148,9 +142,7 @@ export const projectFields = [ operation: [ 'get', ], - resource: [ - 'project', - ], + resource, }, }, description: 'The ID of the project you are retrieving.', @@ -170,9 +162,7 @@ export const projectFields = [ operation: [ 'delete', ], - resource: [ - 'project', - ], + resource, }, }, description: 'The ID of the project want to delete.', diff --git a/packages/nodes-base/nodes/Harvest/TaskDescription.ts b/packages/nodes-base/nodes/Harvest/TaskDescription.ts index b8aea2fcd6..feb404d8b5 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' ]; export const taskOperations = [ { displayName: 'Operation', @@ -7,9 +7,7 @@ export const taskOperations = [ type: 'options', displayOptions: { show: { - resource: [ - 'task', - ], + resource, }, }, options: [ @@ -47,9 +45,7 @@ export const taskFields = [ type: 'boolean', displayOptions: { show: { - resource: [ - 'task', - ], + resource, operation: [ 'getAll', ], @@ -64,9 +60,7 @@ export const taskFields = [ type: 'number', displayOptions: { show: { - resource: [ - 'task', - ], + resource, operation: [ 'getAll', ], @@ -90,9 +84,7 @@ export const taskFields = [ default: {}, displayOptions: { show: { - resource: [ - 'task', - ], + resource, operation: [ 'getAll', ], @@ -140,9 +132,7 @@ export const taskFields = [ operation: [ 'get', ], - resource: [ - 'task', - ], + resource, }, }, description: 'The ID of the task you are retrieving.', @@ -162,9 +152,7 @@ export const taskFields = [ operation: [ 'delete', ], - resource: [ - 'task', - ], + resource, }, }, description: 'The ID of the task you wan to delete.',