diff --git a/packages/nodes-base/nodes/Harvest/ClientDescription.ts b/packages/nodes-base/nodes/Harvest/ClientDescription.ts index 1cefde7dad..a8de15c92f 100644 --- a/packages/nodes-base/nodes/Harvest/ClientDescription.ts +++ b/packages/nodes-base/nodes/Harvest/ClientDescription.ts @@ -24,7 +24,7 @@ export const clientOperations = [ description: 'Get data of all clients', }, ], - default: 'create', + default: 'getAll', description: 'The operation to perform.', }, diff --git a/packages/nodes-base/nodes/Harvest/CompanyDescription.ts b/packages/nodes-base/nodes/Harvest/CompanyDescription.ts index 6b85e78bcb..26303b7eb3 100644 --- a/packages/nodes-base/nodes/Harvest/CompanyDescription.ts +++ b/packages/nodes-base/nodes/Harvest/CompanyDescription.ts @@ -1,6 +1,6 @@ import { INodeProperties } from "n8n-workflow"; -export const clientOperations = [ +export const companyOperations = [ { displayName: 'Operation', name: 'operation', diff --git a/packages/nodes-base/nodes/Harvest/ContactDescription.ts b/packages/nodes-base/nodes/Harvest/ContactDescription.ts index aa926d233d..f4156eeb1c 100644 --- a/packages/nodes-base/nodes/Harvest/ContactDescription.ts +++ b/packages/nodes-base/nodes/Harvest/ContactDescription.ts @@ -24,7 +24,7 @@ export const contactOperations = [ description: 'Get data of all contacts', }, ], - default: 'create', + default: 'getAll', description: 'The operation to perform.', }, @@ -115,7 +115,7 @@ export const contactFields = [ /* contact:get */ /* -------------------------------------------------------------------------- */ { - displayName: 'Client Id', + displayName: 'Contact Id', name: 'id', type: 'string', default: '', diff --git a/packages/nodes-base/nodes/Harvest/EstimateDescription.ts b/packages/nodes-base/nodes/Harvest/EstimateDescription.ts new file mode 100644 index 0000000000..e16d8ab6c3 --- /dev/null +++ b/packages/nodes-base/nodes/Harvest/EstimateDescription.ts @@ -0,0 +1,164 @@ +import { INodeProperties } from "n8n-workflow"; + +export const estimateOperations = [ + { + displayName: 'Operation', + name: 'operation', + type: 'options', + displayOptions: { + show: { + resource: [ + 'estimate', + ], + }, + }, + options: [ + { + name: 'Get', + value: 'get', + description: 'Get data of an estimate', + }, + { + name: 'Get All', + value: 'getAll', + description: 'Get data of all estimates', + }, + ], + default: 'getAll', + description: 'The operation to perform.', + }, + +] as INodeProperties[]; + +export const estimateFields = [ + +/* -------------------------------------------------------------------------- */ +/* estimate:getAll */ +/* -------------------------------------------------------------------------- */ + +{ + displayName: 'Return All', + name: 'returnAll', + type: 'boolean', + displayOptions: { + show: { + resource: [ + 'estimate', + ], + operation: [ + 'getAll', + ], + }, + }, + default: false, + description: 'Returns a list of your estimates.', +}, +{ + displayName: 'Limit', + name: 'limit', + type: 'number', + displayOptions: { + show: { + resource: [ + 'estimate', + ], + 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: [ + 'estimate', + ], + operation: [ + 'getAll', + ], + }, + }, + options: [ + { + displayName: 'Client ID', + name: 'client_id', + type: 'string', + default: '', + description: 'Only return time entries belonging to the client with the given ID.', + }, + { + displayName: 'Updated Since', + name: 'updated_since', + type: 'string', + default: '', + description: 'Only return time entries that have been updated since the given date and time.', + }, + { + displayName: 'From', + name: 'from', + type: 'dateTime', + default: '', + description: 'Only return time entries with a spent_date on or after the given date.', + }, + { + displayName: 'To', + name: 'to', + type: 'dateTime', + default: '', + description: 'Only return time entries with a spent_date on or before the given date.', + }, + { + displayName: 'State', + name: 'state', + type: 'string', + default: '', + description: 'Only return estimates with a state matching the value provided. Options: draft, sent, accepted, or declined.', + }, + { + displayName: 'Page', + name: 'page', + type: 'string', + default: '', + description: 'The page number to use in pagination. For instance, if you make a list request and receive 100 records, your subsequent call can include page=2 to retrieve the next page of the list. (Default: 1)', + } + ] +}, + +/* -------------------------------------------------------------------------- */ +/* estimate:get */ +/* -------------------------------------------------------------------------- */ +{ + displayName: 'Estimate Id', + name: 'id', + type: 'string', + default: '', + required: true, + displayOptions: { + show: { + operation: [ + 'get', + ], + resource: [ + 'estimate', + ], + }, + }, + description: 'The ID of the estimate you are retrieving.', +} + +] as INodeProperties[]; diff --git a/packages/nodes-base/nodes/Harvest/ExpenseDescription.ts b/packages/nodes-base/nodes/Harvest/ExpenseDescription.ts index 609a93f6b3..831d617bbf 100644 --- a/packages/nodes-base/nodes/Harvest/ExpenseDescription.ts +++ b/packages/nodes-base/nodes/Harvest/ExpenseDescription.ts @@ -16,7 +16,7 @@ export const expenseOperations = [ { name: 'Get', value: 'get', - description: 'Get data of a expense', + description: 'Get data of an expense', }, { name: 'Get All', @@ -24,7 +24,7 @@ export const expenseOperations = [ description: 'Get data of all expenses', }, ], - default: 'create', + default: 'getAll', description: 'The operation to perform.', }, @@ -157,7 +157,7 @@ export const expenseFields = [ /* expense:get */ /* -------------------------------------------------------------------------- */ { - displayName: 'Client Id', + displayName: 'Expense Id', name: 'id', type: 'string', default: '', diff --git a/packages/nodes-base/nodes/Harvest/Harvest.node.ts b/packages/nodes-base/nodes/Harvest/Harvest.node.ts index 4d42ec6070..b1e662fc5d 100644 --- a/packages/nodes-base/nodes/Harvest/Harvest.node.ts +++ b/packages/nodes-base/nodes/Harvest/Harvest.node.ts @@ -10,6 +10,15 @@ import { import { harvestApiRequest } from './GenericFunctions'; import { timeEntryOperations, timeEntryFields } from './TimeEntryDescription'; +import { clientOperations, clientFields } from './ClientDescription'; +import { companyOperations } from './CompanyDescription'; +import { contactOperations, contactFields } from './ContactDescription'; +import { expenseOperations, expenseFields } from './ExpenseDescription'; +import { invoiceOperations, invoiceFields } from './InvoiceDescription'; +import { projectOperations, projectFields } from './ProjectDescription'; +import { taskOperations, taskFields } from './TaskDescription'; +import { userOperations, userFields } from './UserDescription'; +import { estimateOperations, estimateFields } from './EstimateDescription'; export class Harvest implements INodeType { @@ -47,33 +56,65 @@ export class Harvest implements INodeType { name: "Client", value: "client" }, - { name: "Project", - value: "project"}, - { name: "Contact", - value: "contact"}, - { name: "Company", - value: "company"}, - { name: "Invoice", - value: "invoice"}, - { name: "Task", - value: "task"}, - { name: "User", - value: "user"}, - { name: "Expense", - value: "expense"}, - { name: "Estimates", - value: "estimate"} + { + name: "Project", + value: "project" + }, + { + name: "Contact", + value: "contact" + }, + { + name: "Company", + value: "company" + }, + { + name: "Invoice", + value: "invoice" + }, + { + name: "Task", + value: "task" + }, + { + name: "User", + value: "user" + }, + { + name: "Expense", + value: "expense" + }, + { + name: "Estimates", + value: "estimate" + } ], - default: 'timeEntry', + default: 'user', description: 'The resource to operate on.', }, // operations + ...clientOperations, + ...companyOperations, + ...contactOperations, + ...estimateOperations, + ...expenseOperations, + ...invoiceOperations, + ...projectOperations, + ...taskOperations, ...timeEntryOperations, - ...compa + ...userOperations, // fields - ...timeEntryFields + ...clientFields, + ...contactFields, + ...estimateFields, + ...expenseFields, + ...invoiceFields, + ...projectFields, + ...taskFields, + ...timeEntryFields, + ...userFields ] }; @@ -292,7 +333,7 @@ export class Harvest implements INodeType { try { let responseData = await harvestApiRequest.call(this, requestMethod, qs, endpoint); - returnData.push.apply(returnData, responseData.time_entries as IDataObject[]); + returnData.push.apply(returnData, responseData.clients as IDataObject[]); } catch (error) { throw error; } @@ -334,7 +375,7 @@ export class Harvest implements INodeType { try { let responseData = await harvestApiRequest.call(this, requestMethod, qs, endpoint); - returnData.push.apply(returnData, responseData.time_entries as IDataObject[]); + returnData.push.apply(returnData, responseData.projects as IDataObject[]); } catch (error) { throw error; } @@ -376,14 +417,14 @@ export class Harvest implements INodeType { try { let responseData = await harvestApiRequest.call(this, requestMethod, qs, endpoint); - returnData.push.apply(returnData, responseData.time_entries as IDataObject[]); + returnData.push.apply(returnData, responseData.users as IDataObject[]); } catch (error) { throw error; } } else if (operation === 'me') { // ---------------------------------- - // getAll + // me // ---------------------------------- requestMethod = 'GET'; @@ -392,7 +433,7 @@ export class Harvest implements INodeType { try { let responseData = await harvestApiRequest.call(this, requestMethod, qs, endpoint); - returnData.push.apply(responseData); + returnData.push(responseData); } catch (error) { throw error; } @@ -434,7 +475,7 @@ export class Harvest implements INodeType { try { let responseData = await harvestApiRequest.call(this, requestMethod, qs, endpoint); - returnData.push.apply(returnData, responseData.time_entries as IDataObject[]); + returnData.push.apply(returnData, responseData.contacts as IDataObject[]); } catch (error) { throw error; } @@ -449,8 +490,6 @@ export class Harvest implements INodeType { // ---------------------------------- requestMethod = 'GET'; - const id = this.getNodeParameter('id', i) as string; - endpoint = `company`; try { @@ -497,7 +536,7 @@ export class Harvest implements INodeType { try { let responseData = await harvestApiRequest.call(this, requestMethod, qs, endpoint); - returnData.push.apply(returnData, responseData.time_entries as IDataObject[]); + returnData.push.apply(returnData, responseData.companies as IDataObject[]); } catch (error) { throw error; } @@ -539,7 +578,7 @@ export class Harvest implements INodeType { try { let responseData = await harvestApiRequest.call(this, requestMethod, qs, endpoint); - returnData.push.apply(returnData, responseData.time_entries as IDataObject[]); + returnData.push.apply(returnData, responseData.invoices as IDataObject[]); } catch (error) { throw error; } @@ -581,7 +620,49 @@ export class Harvest implements INodeType { try { let responseData = await harvestApiRequest.call(this, requestMethod, qs, endpoint); - returnData.push.apply(returnData, responseData.time_entries as IDataObject[]); + returnData.push.apply(returnData, responseData.expenses as IDataObject[]); + } catch (error) { + throw error; + } + + } else { + throw new Error(`The resource "${resource}" is not known!`); + } + } else if (resource === 'estimate') { + if (operation === 'get') { + // ---------------------------------- + // get + // ---------------------------------- + + requestMethod = 'GET'; + const id = this.getNodeParameter('id', i) as string; + + endpoint = `estimates/${id}`; + + try { + const responseData = await harvestApiRequest.call(this, requestMethod, qs, endpoint); + returnData.push(responseData); + } catch (error) { + throw error; + } + + } else if (operation === 'getAll') { + // ---------------------------------- + // getAll + // ---------------------------------- + + requestMethod = 'GET'; + + endpoint = 'estimates'; + + const additionalFields = this.getNodeParameter('filters', i) as IDataObject; + const limit = this.getNodeParameter('limit', i) as string; + qs.per_page = limit; + Object.assign(qs, additionalFields); + + try { + let responseData = await harvestApiRequest.call(this, requestMethod, qs, endpoint); + returnData.push.apply(returnData, responseData.estimates as IDataObject[]); } catch (error) { throw error; } diff --git a/packages/nodes-base/nodes/Harvest/InvoiceDescription.ts b/packages/nodes-base/nodes/Harvest/InvoiceDescription.ts index edc710afeb..d125d22fe4 100644 --- a/packages/nodes-base/nodes/Harvest/InvoiceDescription.ts +++ b/packages/nodes-base/nodes/Harvest/InvoiceDescription.ts @@ -24,7 +24,7 @@ export const invoiceOperations = [ description: 'Get data of all invoices', }, ], - default: 'create', + default: 'getAll', description: 'The operation to perform.', }, @@ -168,7 +168,7 @@ export const invoiceFields = [ /* invoice:get */ /* -------------------------------------------------------------------------- */ { - displayName: 'Client Id', + displayName: 'Invoice Id', name: 'id', type: 'string', default: '', diff --git a/packages/nodes-base/nodes/Harvest/ProjectDescription.ts b/packages/nodes-base/nodes/Harvest/ProjectDescription.ts index 3cbc6536fb..e4c43c94eb 100644 --- a/packages/nodes-base/nodes/Harvest/ProjectDescription.ts +++ b/packages/nodes-base/nodes/Harvest/ProjectDescription.ts @@ -24,7 +24,7 @@ export const projectOperations = [ description: 'Get data of all projects', }, ], - default: 'create', + default: 'getAll', description: 'The operation to perform.', }, @@ -130,7 +130,7 @@ export const projectFields = [ /* project:get */ /* -------------------------------------------------------------------------- */ { - displayName: 'Client Id', + displayName: 'Project Id', name: 'id', type: 'string', default: '', diff --git a/packages/nodes-base/nodes/Harvest/TaskDescription.ts b/packages/nodes-base/nodes/Harvest/TaskDescription.ts index e1c3020ea3..f953a35137 100644 --- a/packages/nodes-base/nodes/Harvest/TaskDescription.ts +++ b/packages/nodes-base/nodes/Harvest/TaskDescription.ts @@ -24,7 +24,7 @@ export const taskOperations = [ description: 'Get data of all tasks', }, ], - default: 'create', + default: 'getAll', description: 'The operation to perform.', }, @@ -122,7 +122,7 @@ export const taskFields = [ /* task:get */ /* -------------------------------------------------------------------------- */ { - displayName: 'Client Id', + displayName: 'Task Id', name: 'id', type: 'string', default: '', diff --git a/packages/nodes-base/nodes/Harvest/TimeEntryDescription.ts b/packages/nodes-base/nodes/Harvest/TimeEntryDescription.ts index 39b3e07ca5..121a9defe2 100644 --- a/packages/nodes-base/nodes/Harvest/TimeEntryDescription.ts +++ b/packages/nodes-base/nodes/Harvest/TimeEntryDescription.ts @@ -59,7 +59,7 @@ export const timeEntryOperations = [ description: 'Update a time entry', }, ], - default: 'create', + default: 'getAll', description: 'The operation to perform.', }, ] as INodeProperties[]; diff --git a/packages/nodes-base/nodes/Harvest/UserDescription.ts b/packages/nodes-base/nodes/Harvest/UserDescription.ts index d78421e094..2a157a47ff 100644 --- a/packages/nodes-base/nodes/Harvest/UserDescription.ts +++ b/packages/nodes-base/nodes/Harvest/UserDescription.ts @@ -29,7 +29,7 @@ export const userOperations = [ description: 'Get data of all users', }, ], - default: 'create', + default: 'me', description: 'The operation to perform.', }, @@ -127,7 +127,7 @@ export const userFields = [ /* user:get */ /* -------------------------------------------------------------------------- */ { - displayName: 'Client Id', + displayName: 'User Id', name: 'id', type: 'string', default: '',