2022-08-17 08:50:24 -07:00
|
|
|
import { IExecuteFunctions, ILoadOptionsFunctions } from 'n8n-core';
|
2020-11-24 05:15:47 -08:00
|
|
|
|
2020-01-28 06:46:38 -08:00
|
|
|
import {
|
|
|
|
IDataObject,
|
|
|
|
INodeExecutionData,
|
2020-11-24 05:15:47 -08:00
|
|
|
INodePropertyOptions,
|
2020-01-28 06:46:38 -08:00
|
|
|
INodeType,
|
2020-10-01 05:01:39 -07:00
|
|
|
INodeTypeDescription,
|
2021-04-16 09:33:36 -07:00
|
|
|
NodeOperationError,
|
2020-01-28 06:46:38 -08:00
|
|
|
} from 'n8n-workflow';
|
|
|
|
|
2022-08-17 08:50:24 -07:00
|
|
|
import { clientFields, clientOperations } from './ClientDescription';
|
2020-11-24 05:15:47 -08:00
|
|
|
|
2022-08-17 08:50:24 -07:00
|
|
|
import { contactFields, contactOperations } from './ContactDescription';
|
2020-11-24 05:15:47 -08:00
|
|
|
|
2022-08-17 08:50:24 -07:00
|
|
|
import { companyOperations } from './CompanyDescription';
|
2020-11-24 05:15:47 -08:00
|
|
|
|
2022-08-17 08:50:24 -07:00
|
|
|
import { estimateFields, estimateOperations } from './EstimateDescription';
|
2020-11-24 05:15:47 -08:00
|
|
|
|
2022-08-17 08:50:24 -07:00
|
|
|
import { expenseFields, expenseOperations } from './ExpenseDescription';
|
2020-11-24 05:15:47 -08:00
|
|
|
|
2022-08-17 08:50:24 -07:00
|
|
|
import { getAllResource, harvestApiRequest } from './GenericFunctions';
|
2020-11-24 05:15:47 -08:00
|
|
|
|
2022-08-17 08:50:24 -07:00
|
|
|
import { invoiceFields, invoiceOperations } from './InvoiceDescription';
|
2020-11-24 05:15:47 -08:00
|
|
|
|
2022-08-17 08:50:24 -07:00
|
|
|
import { projectFields, projectOperations } from './ProjectDescription';
|
2020-11-24 05:15:47 -08:00
|
|
|
|
2022-08-17 08:50:24 -07:00
|
|
|
import { taskFields, taskOperations } from './TaskDescription';
|
2021-04-02 08:56:45 -07:00
|
|
|
|
2022-08-17 08:50:24 -07:00
|
|
|
import { timeEntryFields, timeEntryOperations } from './TimeEntryDescription';
|
2020-11-24 05:15:47 -08:00
|
|
|
|
2022-08-17 08:50:24 -07:00
|
|
|
import { userFields, userOperations } from './UserDescription';
|
2020-01-28 06:46:38 -08:00
|
|
|
|
|
|
|
export class Harvest implements INodeType {
|
|
|
|
description: INodeTypeDescription = {
|
|
|
|
displayName: 'Harvest',
|
|
|
|
name: 'harvest',
|
2022-06-20 07:54:01 -07:00
|
|
|
// eslint-disable-next-line n8n-nodes-base/node-class-description-icon-not-svg
|
2020-01-28 06:46:38 -08:00
|
|
|
icon: 'file:harvest.png',
|
|
|
|
group: ['input'],
|
|
|
|
version: 1,
|
|
|
|
subtitle: '={{$parameter["operation"] + ": " + $parameter["resource"]}}',
|
|
|
|
description: 'Access data on Harvest',
|
|
|
|
defaults: {
|
|
|
|
name: 'Harvest',
|
|
|
|
},
|
|
|
|
inputs: ['main'],
|
|
|
|
outputs: ['main'],
|
|
|
|
credentials: [
|
|
|
|
{
|
|
|
|
name: 'harvestApi',
|
|
|
|
required: true,
|
2020-11-24 05:15:47 -08:00
|
|
|
displayOptions: {
|
|
|
|
show: {
|
2022-08-17 08:50:24 -07:00
|
|
|
authentication: ['accessToken'],
|
2020-11-24 05:15:47 -08:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'harvestOAuth2Api',
|
|
|
|
required: true,
|
|
|
|
displayOptions: {
|
|
|
|
show: {
|
2022-08-17 08:50:24 -07:00
|
|
|
authentication: ['oAuth2'],
|
2020-11-24 05:15:47 -08:00
|
|
|
},
|
|
|
|
},
|
2020-10-22 06:46:03 -07:00
|
|
|
},
|
2020-01-28 06:46:38 -08:00
|
|
|
],
|
|
|
|
properties: [
|
2020-11-24 05:15:47 -08:00
|
|
|
{
|
|
|
|
displayName: 'Authentication',
|
|
|
|
name: 'authentication',
|
|
|
|
type: 'options',
|
|
|
|
options: [
|
|
|
|
{
|
|
|
|
name: 'Access Token',
|
|
|
|
value: 'accessToken',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'OAuth2',
|
|
|
|
value: 'oAuth2',
|
|
|
|
},
|
|
|
|
],
|
|
|
|
default: 'accessToken',
|
|
|
|
},
|
|
|
|
|
2020-01-28 06:46:38 -08:00
|
|
|
{
|
|
|
|
displayName: 'Resource',
|
|
|
|
name: 'resource',
|
|
|
|
type: 'options',
|
2022-05-20 14:47:24 -07:00
|
|
|
noDataExpression: true,
|
2020-01-28 06:46:38 -08:00
|
|
|
options: [
|
|
|
|
{
|
2020-01-29 15:51:14 -08:00
|
|
|
name: 'Client',
|
2020-02-07 20:38:13 -08:00
|
|
|
value: 'client',
|
2020-01-28 06:46:38 -08:00
|
|
|
},
|
2020-01-28 07:50:15 -08:00
|
|
|
{
|
2020-01-29 15:51:14 -08:00
|
|
|
name: 'Company',
|
2020-02-07 20:38:13 -08:00
|
|
|
value: 'company',
|
2020-01-28 07:50:15 -08:00
|
|
|
},
|
2020-01-28 23:04:52 -08:00
|
|
|
{
|
2020-01-29 15:51:14 -08:00
|
|
|
name: 'Contact',
|
2020-02-07 20:38:13 -08:00
|
|
|
value: 'contact',
|
2020-01-28 23:04:52 -08:00
|
|
|
},
|
|
|
|
{
|
2020-02-07 20:38:13 -08:00
|
|
|
name: 'Estimate',
|
|
|
|
value: 'estimate',
|
2020-01-28 23:04:52 -08:00
|
|
|
},
|
|
|
|
{
|
2020-01-29 15:51:14 -08:00
|
|
|
name: 'Expense',
|
2020-02-07 20:38:13 -08:00
|
|
|
value: 'expense',
|
2020-01-28 23:04:52 -08:00
|
|
|
},
|
|
|
|
{
|
2020-01-29 15:51:14 -08:00
|
|
|
name: 'Invoice',
|
2020-02-07 20:38:13 -08:00
|
|
|
value: 'invoice',
|
2020-01-28 23:04:52 -08:00
|
|
|
},
|
|
|
|
{
|
2020-01-29 15:51:14 -08:00
|
|
|
name: 'Project',
|
2020-02-07 20:38:13 -08:00
|
|
|
value: 'project',
|
2020-01-28 23:04:52 -08:00
|
|
|
},
|
|
|
|
{
|
2020-01-29 15:51:14 -08:00
|
|
|
name: 'Task',
|
2020-02-07 20:38:13 -08:00
|
|
|
value: 'task',
|
2020-01-28 23:04:52 -08:00
|
|
|
},
|
|
|
|
{
|
2022-05-20 14:47:24 -07:00
|
|
|
name: 'Time Entry',
|
2020-02-07 20:38:13 -08:00
|
|
|
value: 'timeEntry',
|
2020-01-28 23:04:52 -08:00
|
|
|
},
|
|
|
|
{
|
2020-01-29 15:51:14 -08:00
|
|
|
name: 'User',
|
2020-02-07 20:38:13 -08:00
|
|
|
value: 'user',
|
2020-01-29 15:51:14 -08:00
|
|
|
},
|
2020-01-28 06:46:38 -08:00
|
|
|
],
|
2020-02-07 20:38:13 -08:00
|
|
|
default: 'task',
|
2020-01-28 06:46:38 -08:00
|
|
|
},
|
|
|
|
|
|
|
|
// operations
|
2020-01-28 23:04:52 -08:00
|
|
|
...clientOperations,
|
|
|
|
...companyOperations,
|
|
|
|
...contactOperations,
|
|
|
|
...estimateOperations,
|
|
|
|
...expenseOperations,
|
|
|
|
...invoiceOperations,
|
|
|
|
...projectOperations,
|
|
|
|
...taskOperations,
|
2020-01-28 06:46:38 -08:00
|
|
|
...timeEntryOperations,
|
2020-01-28 23:04:52 -08:00
|
|
|
...userOperations,
|
2020-01-28 06:46:38 -08:00
|
|
|
|
2021-04-02 09:10:22 -07:00
|
|
|
{
|
2022-06-03 10:23:49 -07:00
|
|
|
displayName: 'Account Name or ID',
|
2021-04-02 09:10:22 -07:00
|
|
|
name: 'accountId',
|
|
|
|
type: 'options',
|
2022-08-17 08:50:24 -07:00
|
|
|
description:
|
|
|
|
'Choose from the list, or specify an ID using an <a href="https://docs.n8n.io/code-examples/expressions/">expression</a>',
|
2021-04-02 09:10:22 -07:00
|
|
|
required: true,
|
|
|
|
typeOptions: {
|
|
|
|
loadOptionsMethod: 'getAccounts',
|
|
|
|
},
|
|
|
|
default: '',
|
|
|
|
},
|
|
|
|
|
2020-01-28 06:46:38 -08:00
|
|
|
// fields
|
2020-01-28 23:04:52 -08:00
|
|
|
...clientFields,
|
|
|
|
...contactFields,
|
|
|
|
...estimateFields,
|
|
|
|
...expenseFields,
|
|
|
|
...invoiceFields,
|
|
|
|
...projectFields,
|
|
|
|
...taskFields,
|
|
|
|
...timeEntryFields,
|
2020-10-22 06:46:03 -07:00
|
|
|
...userFields,
|
|
|
|
],
|
2020-01-28 06:46:38 -08:00
|
|
|
};
|
|
|
|
|
2020-11-24 05:15:47 -08:00
|
|
|
methods = {
|
|
|
|
loadOptions: {
|
|
|
|
// Get all the available accounts to display them to user so that he can
|
|
|
|
// select them easily
|
|
|
|
async getAccounts(this: ILoadOptionsFunctions): Promise<INodePropertyOptions[]> {
|
|
|
|
const returnData: INodePropertyOptions[] = [];
|
2022-08-17 08:50:24 -07:00
|
|
|
const { accounts } = await harvestApiRequest.call(
|
|
|
|
this,
|
|
|
|
'GET',
|
|
|
|
{},
|
|
|
|
'',
|
|
|
|
{},
|
|
|
|
{},
|
|
|
|
'https://id.getharvest.com/api/v2/accounts',
|
|
|
|
);
|
2020-11-24 05:15:47 -08:00
|
|
|
for (const account of accounts) {
|
|
|
|
const accountName = account.name;
|
|
|
|
const accountId = account.id;
|
|
|
|
returnData.push({
|
|
|
|
name: accountName,
|
|
|
|
value: accountId,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
return returnData;
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2020-01-28 06:46:38 -08:00
|
|
|
async execute(this: IExecuteFunctions): Promise<INodeExecutionData[][]> {
|
|
|
|
const items = this.getInputData();
|
2022-08-30 08:55:33 -07:00
|
|
|
const returnData: INodeExecutionData[] = [];
|
2020-01-28 06:46:38 -08:00
|
|
|
|
2022-12-02 03:53:59 -08:00
|
|
|
const resource = this.getNodeParameter('resource', 0);
|
|
|
|
const operation = this.getNodeParameter('operation', 0);
|
2020-01-28 06:46:38 -08:00
|
|
|
|
|
|
|
let endpoint = '';
|
|
|
|
let requestMethod = '';
|
|
|
|
let body: IDataObject | Buffer;
|
|
|
|
let qs: IDataObject;
|
|
|
|
|
|
|
|
for (let i = 0; i < items.length; i++) {
|
2021-07-19 23:58:54 -07:00
|
|
|
try {
|
|
|
|
body = {};
|
|
|
|
qs = {};
|
|
|
|
|
|
|
|
if (resource === 'timeEntry') {
|
|
|
|
if (operation === 'get') {
|
|
|
|
// ----------------------------------
|
|
|
|
// get
|
|
|
|
// ----------------------------------
|
2020-01-28 06:46:38 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
requestMethod = 'GET';
|
|
|
|
const id = this.getNodeParameter('id', i) as string;
|
2020-01-28 06:46:38 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
endpoint = `time_entries/${id}`;
|
2020-01-28 06:46:38 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
const responseData = await harvestApiRequest.call(this, requestMethod, qs, endpoint);
|
2022-08-30 08:55:33 -07:00
|
|
|
const executionData = this.helpers.constructExecutionMetaData(
|
|
|
|
this.helpers.returnJsonArray(responseData),
|
|
|
|
{ itemData: { item: i } },
|
|
|
|
);
|
|
|
|
|
|
|
|
returnData.push(...executionData);
|
2021-07-19 23:58:54 -07:00
|
|
|
} else if (operation === 'getAll') {
|
|
|
|
// ----------------------------------
|
|
|
|
// getAll
|
|
|
|
// ----------------------------------
|
|
|
|
const responseData: IDataObject[] = await getAllResource.call(this, 'time_entries', i);
|
2022-08-30 08:55:33 -07:00
|
|
|
const executionData = this.helpers.constructExecutionMetaData(
|
|
|
|
this.helpers.returnJsonArray(responseData),
|
|
|
|
{ itemData: { item: i } },
|
|
|
|
);
|
|
|
|
|
|
|
|
returnData.push(...executionData);
|
2021-07-19 23:58:54 -07:00
|
|
|
} else if (operation === 'createByStartEnd') {
|
|
|
|
// ----------------------------------
|
|
|
|
// createByStartEnd
|
|
|
|
// ----------------------------------
|
2020-01-28 06:46:38 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
requestMethod = 'POST';
|
|
|
|
endpoint = 'time_entries';
|
2020-01-28 06:46:38 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
body.project_id = this.getNodeParameter('projectId', i) as string;
|
|
|
|
body.task_id = this.getNodeParameter('taskId', i) as string;
|
|
|
|
body.spent_date = this.getNodeParameter('spentDate', i) as string;
|
2020-01-28 06:46:38 -08:00
|
|
|
|
2022-11-18 07:29:44 -08:00
|
|
|
const additionalFields = this.getNodeParameter('additionalFields', i);
|
2021-07-19 23:58:54 -07:00
|
|
|
Object.assign(body, additionalFields);
|
2020-01-28 06:46:38 -08:00
|
|
|
|
2022-08-17 08:50:24 -07:00
|
|
|
const responseData = await harvestApiRequest.call(
|
|
|
|
this,
|
|
|
|
requestMethod,
|
|
|
|
qs,
|
|
|
|
endpoint,
|
|
|
|
body,
|
|
|
|
);
|
2022-08-30 08:55:33 -07:00
|
|
|
const executionData = this.helpers.constructExecutionMetaData(
|
|
|
|
this.helpers.returnJsonArray(responseData),
|
|
|
|
{ itemData: { item: i } },
|
|
|
|
);
|
|
|
|
|
|
|
|
returnData.push(...executionData);
|
2021-07-19 23:58:54 -07:00
|
|
|
} else if (operation === 'createByDuration') {
|
|
|
|
// ----------------------------------
|
|
|
|
// createByDuration
|
|
|
|
// ----------------------------------
|
2020-01-28 06:46:38 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
requestMethod = 'POST';
|
|
|
|
endpoint = 'time_entries';
|
2020-01-28 06:46:38 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
body.project_id = this.getNodeParameter('projectId', i) as string;
|
|
|
|
body.task_id = this.getNodeParameter('taskId', i) as string;
|
|
|
|
body.spent_date = this.getNodeParameter('spentDate', i) as string;
|
2020-01-28 06:46:38 -08:00
|
|
|
|
2022-11-18 07:29:44 -08:00
|
|
|
const additionalFields = this.getNodeParameter('additionalFields', i);
|
2021-07-19 23:58:54 -07:00
|
|
|
Object.assign(body, additionalFields);
|
2020-01-28 06:46:38 -08:00
|
|
|
|
2022-08-17 08:50:24 -07:00
|
|
|
const responseData = await harvestApiRequest.call(
|
|
|
|
this,
|
|
|
|
requestMethod,
|
|
|
|
qs,
|
|
|
|
endpoint,
|
|
|
|
body,
|
|
|
|
);
|
2022-08-30 08:55:33 -07:00
|
|
|
|
|
|
|
const executionData = this.helpers.constructExecutionMetaData(
|
|
|
|
this.helpers.returnJsonArray(responseData),
|
|
|
|
{ itemData: { item: i } },
|
|
|
|
);
|
|
|
|
|
|
|
|
returnData.push(...executionData);
|
2021-07-19 23:58:54 -07:00
|
|
|
} else if (operation === 'delete') {
|
|
|
|
// ----------------------------------
|
|
|
|
// delete
|
|
|
|
// ----------------------------------
|
2020-01-28 06:46:38 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
requestMethod = 'DELETE';
|
|
|
|
const id = this.getNodeParameter('id', i) as string;
|
|
|
|
endpoint = `time_entries/${id}`;
|
2020-01-28 06:46:38 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
const responseData = await harvestApiRequest.call(this, requestMethod, qs, endpoint);
|
2022-08-30 08:55:33 -07:00
|
|
|
|
|
|
|
const executionData = this.helpers.constructExecutionMetaData(
|
|
|
|
this.helpers.returnJsonArray(responseData),
|
|
|
|
{ itemData: { item: i } },
|
|
|
|
);
|
|
|
|
|
|
|
|
returnData.push(...executionData);
|
2021-07-19 23:58:54 -07:00
|
|
|
} else if (operation === 'deleteExternal') {
|
|
|
|
// ----------------------------------
|
|
|
|
// deleteExternal
|
|
|
|
// ----------------------------------
|
2020-01-28 06:46:38 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
requestMethod = 'DELETE';
|
|
|
|
const id = this.getNodeParameter('id', i) as string;
|
|
|
|
endpoint = `time_entries/${id}/external_reference`;
|
2020-01-28 06:46:38 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
const responseData = await harvestApiRequest.call(this, requestMethod, qs, endpoint);
|
2022-08-30 08:55:33 -07:00
|
|
|
|
|
|
|
const executionData = this.helpers.constructExecutionMetaData(
|
|
|
|
this.helpers.returnJsonArray(responseData),
|
|
|
|
{ itemData: { item: i } },
|
|
|
|
);
|
|
|
|
|
|
|
|
returnData.push(...executionData);
|
2021-07-19 23:58:54 -07:00
|
|
|
} else if (operation === 'restartTime') {
|
|
|
|
// ----------------------------------
|
|
|
|
// restartTime
|
|
|
|
// ----------------------------------
|
2020-01-28 06:46:38 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
requestMethod = 'PATCH';
|
|
|
|
const id = this.getNodeParameter('id', i) as string;
|
|
|
|
endpoint = `time_entries/${id}/restart`;
|
2020-01-28 06:46:38 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
const responseData = await harvestApiRequest.call(this, requestMethod, qs, endpoint);
|
2022-08-30 08:55:33 -07:00
|
|
|
|
|
|
|
const executionData = this.helpers.constructExecutionMetaData(
|
|
|
|
this.helpers.returnJsonArray(responseData),
|
|
|
|
{ itemData: { item: i } },
|
|
|
|
);
|
|
|
|
|
|
|
|
returnData.push(...executionData);
|
2021-07-19 23:58:54 -07:00
|
|
|
} else if (operation === 'stopTime') {
|
|
|
|
// ----------------------------------
|
|
|
|
// stopTime
|
|
|
|
// ----------------------------------
|
2020-01-28 06:46:38 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
requestMethod = 'PATCH';
|
|
|
|
const id = this.getNodeParameter('id', i) as string;
|
|
|
|
endpoint = `time_entries/${id}/stop`;
|
2020-01-28 06:46:38 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
const responseData = await harvestApiRequest.call(this, requestMethod, qs, endpoint);
|
2022-08-30 08:55:33 -07:00
|
|
|
|
|
|
|
const executionData = this.helpers.constructExecutionMetaData(
|
|
|
|
this.helpers.returnJsonArray(responseData),
|
|
|
|
{ itemData: { item: i } },
|
|
|
|
);
|
|
|
|
|
|
|
|
returnData.push(...executionData);
|
2021-07-19 23:58:54 -07:00
|
|
|
} else if (operation === 'update') {
|
|
|
|
// ----------------------------------
|
|
|
|
// update
|
|
|
|
// ----------------------------------
|
2020-01-28 06:46:38 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
requestMethod = 'PATCH';
|
|
|
|
const id = this.getNodeParameter('id', i) as string;
|
|
|
|
endpoint = `time_entries/${id}`;
|
2020-01-28 06:46:38 -08:00
|
|
|
|
2022-11-18 07:29:44 -08:00
|
|
|
const updateFields = this.getNodeParameter('updateFields', i);
|
2020-01-28 06:46:38 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
Object.assign(body, updateFields);
|
2022-08-17 08:50:24 -07:00
|
|
|
const responseData = await harvestApiRequest.call(
|
|
|
|
this,
|
|
|
|
requestMethod,
|
|
|
|
qs,
|
|
|
|
endpoint,
|
|
|
|
body,
|
|
|
|
);
|
2022-08-30 08:55:33 -07:00
|
|
|
|
|
|
|
const executionData = this.helpers.constructExecutionMetaData(
|
|
|
|
this.helpers.returnJsonArray(responseData),
|
|
|
|
{ itemData: { item: i } },
|
|
|
|
);
|
|
|
|
|
|
|
|
returnData.push(...executionData);
|
2021-07-19 23:58:54 -07:00
|
|
|
} else {
|
2022-08-17 08:50:24 -07:00
|
|
|
throw new NodeOperationError(
|
|
|
|
this.getNode(),
|
|
|
|
`The operation "${operation}" is not known!`,
|
|
|
|
{ itemIndex: i },
|
|
|
|
);
|
2021-07-19 23:58:54 -07:00
|
|
|
}
|
|
|
|
} else if (resource === 'client') {
|
|
|
|
if (operation === 'get') {
|
|
|
|
// ----------------------------------
|
|
|
|
// get
|
|
|
|
// ----------------------------------
|
2020-01-28 06:46:38 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
requestMethod = 'GET';
|
|
|
|
const id = this.getNodeParameter('id', i) as string;
|
2020-01-28 07:50:15 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
endpoint = `clients/${id}`;
|
2020-01-28 07:50:15 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
const responseData = await harvestApiRequest.call(this, requestMethod, qs, endpoint);
|
2022-08-30 08:55:33 -07:00
|
|
|
|
|
|
|
const executionData = this.helpers.constructExecutionMetaData(
|
|
|
|
this.helpers.returnJsonArray(responseData),
|
|
|
|
{ itemData: { item: i } },
|
|
|
|
);
|
|
|
|
|
|
|
|
returnData.push(...executionData);
|
2021-07-19 23:58:54 -07:00
|
|
|
} else if (operation === 'getAll') {
|
|
|
|
// ----------------------------------
|
|
|
|
// getAll
|
|
|
|
// ----------------------------------
|
2020-01-28 07:50:15 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
const responseData: IDataObject[] = await getAllResource.call(this, 'clients', i);
|
2022-08-30 08:55:33 -07:00
|
|
|
|
|
|
|
const executionData = this.helpers.constructExecutionMetaData(
|
|
|
|
this.helpers.returnJsonArray(responseData),
|
|
|
|
{ itemData: { item: i } },
|
|
|
|
);
|
|
|
|
|
|
|
|
returnData.push(...executionData);
|
2021-07-19 23:58:54 -07:00
|
|
|
} else if (operation === 'create') {
|
|
|
|
// ----------------------------------
|
|
|
|
// create
|
|
|
|
// ----------------------------------
|
2020-01-28 07:50:15 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
requestMethod = 'POST';
|
|
|
|
endpoint = 'clients';
|
2020-02-03 04:36:51 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
body.name = this.getNodeParameter('name', i) as string;
|
2020-02-03 04:36:51 -08:00
|
|
|
|
2022-11-18 07:29:44 -08:00
|
|
|
const additionalFields = this.getNodeParameter('additionalFields', i);
|
2021-07-19 23:58:54 -07:00
|
|
|
Object.assign(body, additionalFields);
|
2020-02-03 04:36:51 -08:00
|
|
|
|
2022-08-17 08:50:24 -07:00
|
|
|
const responseData = await harvestApiRequest.call(
|
|
|
|
this,
|
|
|
|
requestMethod,
|
|
|
|
qs,
|
|
|
|
endpoint,
|
|
|
|
body,
|
|
|
|
);
|
2022-08-30 08:55:33 -07:00
|
|
|
|
|
|
|
const executionData = this.helpers.constructExecutionMetaData(
|
|
|
|
this.helpers.returnJsonArray(responseData),
|
|
|
|
{ itemData: { item: i } },
|
|
|
|
);
|
|
|
|
|
|
|
|
returnData.push(...executionData);
|
2021-07-19 23:58:54 -07:00
|
|
|
} else if (operation === 'update') {
|
|
|
|
// ----------------------------------
|
|
|
|
// update
|
|
|
|
// ----------------------------------
|
|
|
|
|
|
|
|
requestMethod = 'PATCH';
|
|
|
|
const id = this.getNodeParameter('id', i) as string;
|
|
|
|
endpoint = `clients/${id}`;
|
2020-02-03 04:36:51 -08:00
|
|
|
|
2022-11-18 07:29:44 -08:00
|
|
|
const updateFields = this.getNodeParameter('updateFields', i);
|
2021-07-19 23:58:54 -07:00
|
|
|
Object.assign(qs, updateFields);
|
2020-02-03 04:36:51 -08:00
|
|
|
|
2022-08-17 08:50:24 -07:00
|
|
|
const responseData = await harvestApiRequest.call(
|
|
|
|
this,
|
|
|
|
requestMethod,
|
|
|
|
qs,
|
|
|
|
endpoint,
|
|
|
|
body,
|
|
|
|
);
|
2022-08-30 08:55:33 -07:00
|
|
|
|
|
|
|
const executionData = this.helpers.constructExecutionMetaData(
|
|
|
|
this.helpers.returnJsonArray(responseData),
|
|
|
|
{ itemData: { item: i } },
|
|
|
|
);
|
|
|
|
|
|
|
|
returnData.push(...executionData);
|
2021-07-19 23:58:54 -07:00
|
|
|
} else if (operation === 'delete') {
|
|
|
|
// ----------------------------------
|
|
|
|
// delete
|
|
|
|
// ----------------------------------
|
2020-02-03 04:36:51 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
requestMethod = 'DELETE';
|
|
|
|
const id = this.getNodeParameter('id', i) as string;
|
|
|
|
endpoint = `clients/${id}`;
|
2020-02-03 04:36:51 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
const responseData = await harvestApiRequest.call(this, requestMethod, qs, endpoint);
|
2022-08-30 08:55:33 -07:00
|
|
|
|
|
|
|
const executionData = this.helpers.constructExecutionMetaData(
|
|
|
|
this.helpers.returnJsonArray(responseData),
|
|
|
|
{ itemData: { item: i } },
|
|
|
|
);
|
|
|
|
|
|
|
|
returnData.push(...executionData);
|
2021-07-19 23:58:54 -07:00
|
|
|
} else {
|
2022-08-17 08:50:24 -07:00
|
|
|
throw new NodeOperationError(
|
|
|
|
this.getNode(),
|
|
|
|
`The resource "${resource}" is not known!`,
|
|
|
|
{ itemIndex: i },
|
|
|
|
);
|
2021-07-19 23:58:54 -07:00
|
|
|
}
|
|
|
|
} else if (resource === 'project') {
|
|
|
|
if (operation === 'get') {
|
|
|
|
// ----------------------------------
|
|
|
|
// get
|
|
|
|
// ----------------------------------
|
2020-01-31 04:47:20 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
requestMethod = 'GET';
|
|
|
|
const id = this.getNodeParameter('id', i) as string;
|
2020-01-31 04:47:20 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
endpoint = `projects/${id}`;
|
2020-01-28 07:50:15 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
const responseData = await harvestApiRequest.call(this, requestMethod, qs, endpoint);
|
2022-08-30 08:55:33 -07:00
|
|
|
|
|
|
|
const executionData = this.helpers.constructExecutionMetaData(
|
|
|
|
this.helpers.returnJsonArray(responseData),
|
|
|
|
{ itemData: { item: i } },
|
|
|
|
);
|
|
|
|
|
|
|
|
returnData.push(...executionData);
|
2021-07-19 23:58:54 -07:00
|
|
|
} else if (operation === 'getAll') {
|
|
|
|
// ----------------------------------
|
|
|
|
// getAll
|
|
|
|
// ----------------------------------
|
2020-01-28 07:50:15 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
const responseData: IDataObject[] = await getAllResource.call(this, 'projects', i);
|
2022-08-30 08:55:33 -07:00
|
|
|
|
|
|
|
const executionData = this.helpers.constructExecutionMetaData(
|
|
|
|
this.helpers.returnJsonArray(responseData),
|
|
|
|
{ itemData: { item: i } },
|
|
|
|
);
|
|
|
|
|
|
|
|
returnData.push(...executionData);
|
2021-07-19 23:58:54 -07:00
|
|
|
} else if (operation === 'create') {
|
|
|
|
// ----------------------------------
|
|
|
|
// create
|
|
|
|
// ----------------------------------
|
2020-01-28 07:50:15 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
requestMethod = 'POST';
|
|
|
|
endpoint = 'projects';
|
2020-01-28 07:50:15 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
body.client_id = this.getNodeParameter('clientId', i) as string;
|
|
|
|
body.name = this.getNodeParameter('name', i) as string;
|
|
|
|
body.is_billable = this.getNodeParameter('isBillable', i) as string;
|
|
|
|
body.bill_by = this.getNodeParameter('billBy', i) as string;
|
|
|
|
body.budget_by = this.getNodeParameter('budgetBy', i) as string;
|
2020-02-03 00:39:22 -08:00
|
|
|
|
2022-11-18 07:29:44 -08:00
|
|
|
const additionalFields = this.getNodeParameter('additionalFields', i);
|
2021-07-19 23:58:54 -07:00
|
|
|
Object.assign(body, additionalFields);
|
2020-02-03 00:39:22 -08:00
|
|
|
|
2022-08-17 08:50:24 -07:00
|
|
|
const responseData = await harvestApiRequest.call(
|
|
|
|
this,
|
|
|
|
requestMethod,
|
|
|
|
qs,
|
|
|
|
endpoint,
|
|
|
|
body,
|
|
|
|
);
|
2022-08-30 08:55:33 -07:00
|
|
|
|
|
|
|
const executionData = this.helpers.constructExecutionMetaData(
|
|
|
|
this.helpers.returnJsonArray(responseData),
|
|
|
|
{ itemData: { item: i } },
|
|
|
|
);
|
|
|
|
|
|
|
|
returnData.push(...executionData);
|
2021-07-19 23:58:54 -07:00
|
|
|
} else if (operation === 'update') {
|
|
|
|
// ----------------------------------
|
|
|
|
// update
|
|
|
|
// ----------------------------------
|
2020-02-03 00:39:22 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
requestMethod = 'PATCH';
|
|
|
|
const id = this.getNodeParameter('id', i) as string;
|
|
|
|
endpoint = `projects/${id}`;
|
2020-02-03 00:39:22 -08:00
|
|
|
|
2022-11-18 07:29:44 -08:00
|
|
|
const updateFields = this.getNodeParameter('updateFields', i);
|
2020-02-03 01:23:58 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
Object.assign(body, updateFields);
|
2022-08-17 08:50:24 -07:00
|
|
|
const responseData = await harvestApiRequest.call(
|
|
|
|
this,
|
|
|
|
requestMethod,
|
|
|
|
qs,
|
|
|
|
endpoint,
|
|
|
|
body,
|
|
|
|
);
|
2022-08-30 08:55:33 -07:00
|
|
|
|
|
|
|
const executionData = this.helpers.constructExecutionMetaData(
|
|
|
|
this.helpers.returnJsonArray(responseData),
|
|
|
|
{ itemData: { item: i } },
|
|
|
|
);
|
|
|
|
|
|
|
|
returnData.push(...executionData);
|
2021-07-19 23:58:54 -07:00
|
|
|
} else if (operation === 'delete') {
|
|
|
|
// ----------------------------------
|
|
|
|
// delete
|
|
|
|
// ----------------------------------
|
2020-02-03 01:23:58 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
requestMethod = 'DELETE';
|
|
|
|
const id = this.getNodeParameter('id', i) as string;
|
|
|
|
endpoint = `projects/${id}`;
|
2020-02-03 01:23:58 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
const responseData = await harvestApiRequest.call(this, requestMethod, qs, endpoint);
|
2022-08-30 08:55:33 -07:00
|
|
|
|
|
|
|
const executionData = this.helpers.constructExecutionMetaData(
|
|
|
|
this.helpers.returnJsonArray(responseData),
|
|
|
|
{ itemData: { item: i } },
|
|
|
|
);
|
|
|
|
|
|
|
|
returnData.push(...executionData);
|
2021-07-19 23:58:54 -07:00
|
|
|
} else {
|
2022-08-17 08:50:24 -07:00
|
|
|
throw new NodeOperationError(
|
|
|
|
this.getNode(),
|
|
|
|
`The resource "${resource}" is not known!`,
|
|
|
|
{ itemIndex: i },
|
|
|
|
);
|
2021-07-19 23:58:54 -07:00
|
|
|
}
|
|
|
|
} else if (resource === 'user') {
|
|
|
|
if (operation === 'get') {
|
|
|
|
// ----------------------------------
|
|
|
|
// get
|
|
|
|
// ----------------------------------
|
|
|
|
|
|
|
|
requestMethod = 'GET';
|
|
|
|
const id = this.getNodeParameter('id', i) as string;
|
2020-02-03 01:23:58 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
endpoint = `users/${id}`;
|
2020-01-31 04:47:20 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
const responseData = await harvestApiRequest.call(this, requestMethod, qs, endpoint);
|
2022-08-30 08:55:33 -07:00
|
|
|
|
|
|
|
const executionData = this.helpers.constructExecutionMetaData(
|
|
|
|
this.helpers.returnJsonArray(responseData),
|
|
|
|
{ itemData: { item: i } },
|
|
|
|
);
|
|
|
|
|
|
|
|
returnData.push(...executionData);
|
2021-07-19 23:58:54 -07:00
|
|
|
} else if (operation === 'getAll') {
|
|
|
|
// ----------------------------------
|
|
|
|
// getAll
|
|
|
|
// ----------------------------------
|
2020-01-28 07:50:15 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
const responseData: IDataObject[] = await getAllResource.call(this, 'users', i);
|
2022-08-30 08:55:33 -07:00
|
|
|
|
|
|
|
const executionData = this.helpers.constructExecutionMetaData(
|
|
|
|
this.helpers.returnJsonArray(responseData),
|
|
|
|
{ itemData: { item: i } },
|
|
|
|
);
|
|
|
|
|
|
|
|
returnData.push(...executionData);
|
2021-07-19 23:58:54 -07:00
|
|
|
} else if (operation === 'me') {
|
|
|
|
// ----------------------------------
|
|
|
|
// me
|
|
|
|
// ----------------------------------
|
2020-01-28 07:50:15 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
requestMethod = 'GET';
|
2020-01-28 07:50:15 -08:00
|
|
|
|
2022-12-29 03:20:43 -08:00
|
|
|
endpoint = 'users/me';
|
2020-01-28 07:50:15 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
const responseData = await harvestApiRequest.call(this, requestMethod, qs, endpoint);
|
2022-08-30 08:55:33 -07:00
|
|
|
|
|
|
|
const executionData = this.helpers.constructExecutionMetaData(
|
|
|
|
this.helpers.returnJsonArray(responseData),
|
|
|
|
{ itemData: { item: i } },
|
|
|
|
);
|
|
|
|
|
|
|
|
returnData.push(...executionData);
|
2021-07-19 23:58:54 -07:00
|
|
|
} else if (operation === 'create') {
|
|
|
|
// ----------------------------------
|
|
|
|
// create
|
|
|
|
// ----------------------------------
|
2020-01-28 07:50:15 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
requestMethod = 'POST';
|
|
|
|
endpoint = 'users';
|
2020-01-28 07:50:15 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
body.first_name = this.getNodeParameter('firstName', i) as string;
|
|
|
|
body.last_name = this.getNodeParameter('lastName', i) as string;
|
|
|
|
body.email = this.getNodeParameter('email', i) as string;
|
2020-01-31 05:19:16 -08:00
|
|
|
|
2022-11-18 07:29:44 -08:00
|
|
|
const additionalFields = this.getNodeParameter('additionalFields', i);
|
2021-07-19 23:58:54 -07:00
|
|
|
Object.assign(body, additionalFields);
|
2020-01-31 05:32:14 -08:00
|
|
|
|
2022-08-17 08:50:24 -07:00
|
|
|
const responseData = await harvestApiRequest.call(
|
|
|
|
this,
|
|
|
|
requestMethod,
|
|
|
|
qs,
|
|
|
|
endpoint,
|
|
|
|
body,
|
|
|
|
);
|
2022-08-30 08:55:33 -07:00
|
|
|
|
|
|
|
const executionData = this.helpers.constructExecutionMetaData(
|
|
|
|
this.helpers.returnJsonArray(responseData),
|
|
|
|
{ itemData: { item: i } },
|
|
|
|
);
|
|
|
|
|
|
|
|
returnData.push(...executionData);
|
2021-07-19 23:58:54 -07:00
|
|
|
} else if (operation === 'update') {
|
|
|
|
// ----------------------------------
|
|
|
|
// update
|
|
|
|
// ----------------------------------
|
|
|
|
|
|
|
|
requestMethod = 'PATCH';
|
|
|
|
const id = this.getNodeParameter('id', i) as string;
|
|
|
|
endpoint = `users/${id}`;
|
2020-01-31 05:19:16 -08:00
|
|
|
|
2022-11-18 07:29:44 -08:00
|
|
|
const updateFields = this.getNodeParameter('updateFields', i);
|
2021-07-19 23:58:54 -07:00
|
|
|
Object.assign(qs, updateFields);
|
2020-01-31 05:19:16 -08:00
|
|
|
|
2022-08-17 08:50:24 -07:00
|
|
|
const responseData = await harvestApiRequest.call(
|
|
|
|
this,
|
|
|
|
requestMethod,
|
|
|
|
qs,
|
|
|
|
endpoint,
|
|
|
|
body,
|
|
|
|
);
|
2022-08-30 08:55:33 -07:00
|
|
|
|
|
|
|
const executionData = this.helpers.constructExecutionMetaData(
|
|
|
|
this.helpers.returnJsonArray(responseData),
|
|
|
|
{ itemData: { item: i } },
|
|
|
|
);
|
|
|
|
|
|
|
|
returnData.push(...executionData);
|
2021-07-19 23:58:54 -07:00
|
|
|
} else if (operation === 'delete') {
|
|
|
|
// ----------------------------------
|
|
|
|
// delete
|
|
|
|
// ----------------------------------
|
|
|
|
|
|
|
|
requestMethod = 'DELETE';
|
|
|
|
const id = this.getNodeParameter('id', i) as string;
|
|
|
|
endpoint = `users/${id}`;
|
2020-01-31 05:24:42 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
const responseData = await harvestApiRequest.call(this, requestMethod, qs, endpoint);
|
2022-08-30 08:55:33 -07:00
|
|
|
|
|
|
|
const executionData = this.helpers.constructExecutionMetaData(
|
|
|
|
this.helpers.returnJsonArray(responseData),
|
|
|
|
{ itemData: { item: i } },
|
|
|
|
);
|
|
|
|
|
|
|
|
returnData.push(...executionData);
|
2021-07-19 23:58:54 -07:00
|
|
|
} else {
|
2022-08-17 08:50:24 -07:00
|
|
|
throw new NodeOperationError(
|
|
|
|
this.getNode(),
|
|
|
|
`The resource "${resource}" is not known!`,
|
|
|
|
{ itemIndex: i },
|
|
|
|
);
|
2021-07-19 23:58:54 -07:00
|
|
|
}
|
|
|
|
} else if (resource === 'contact') {
|
|
|
|
if (operation === 'get') {
|
|
|
|
// ----------------------------------
|
|
|
|
// get
|
|
|
|
// ----------------------------------
|
|
|
|
|
|
|
|
requestMethod = 'GET';
|
|
|
|
const id = this.getNodeParameter('id', i) as string;
|
|
|
|
|
|
|
|
endpoint = `contacts/${id}`;
|
|
|
|
|
|
|
|
const responseData = await harvestApiRequest.call(this, requestMethod, qs, endpoint);
|
2022-08-30 08:55:33 -07:00
|
|
|
|
|
|
|
const executionData = this.helpers.constructExecutionMetaData(
|
|
|
|
this.helpers.returnJsonArray(responseData),
|
|
|
|
{ itemData: { item: i } },
|
|
|
|
);
|
|
|
|
|
|
|
|
returnData.push(...executionData);
|
2021-07-19 23:58:54 -07:00
|
|
|
} else if (operation === 'getAll') {
|
|
|
|
// ----------------------------------
|
|
|
|
// getAll
|
|
|
|
// ----------------------------------
|
2020-01-31 05:24:42 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
const responseData: IDataObject[] = await getAllResource.call(this, 'contacts', i);
|
2022-08-30 08:55:33 -07:00
|
|
|
|
|
|
|
const executionData = this.helpers.constructExecutionMetaData(
|
|
|
|
this.helpers.returnJsonArray(responseData),
|
|
|
|
{ itemData: { item: i } },
|
|
|
|
);
|
|
|
|
|
|
|
|
returnData.push(...executionData);
|
2021-07-19 23:58:54 -07:00
|
|
|
} else if (operation === 'create') {
|
|
|
|
// ----------------------------------
|
|
|
|
// create
|
|
|
|
// ----------------------------------
|
2020-01-31 05:19:16 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
requestMethod = 'POST';
|
|
|
|
endpoint = 'contacts';
|
2020-01-31 04:47:20 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
body.client_id = this.getNodeParameter('clientId', i) as string;
|
|
|
|
body.first_name = this.getNodeParameter('firstName', i) as string;
|
2020-01-28 07:50:15 -08:00
|
|
|
|
2022-11-18 07:29:44 -08:00
|
|
|
const additionalFields = this.getNodeParameter('additionalFields', i);
|
2021-07-19 23:58:54 -07:00
|
|
|
Object.assign(body, additionalFields);
|
2020-01-28 07:50:15 -08:00
|
|
|
|
2022-08-17 08:50:24 -07:00
|
|
|
const responseData = await harvestApiRequest.call(
|
|
|
|
this,
|
|
|
|
requestMethod,
|
|
|
|
qs,
|
|
|
|
endpoint,
|
|
|
|
body,
|
|
|
|
);
|
2022-08-30 08:55:33 -07:00
|
|
|
|
|
|
|
const executionData = this.helpers.constructExecutionMetaData(
|
|
|
|
this.helpers.returnJsonArray(responseData),
|
|
|
|
{ itemData: { item: i } },
|
|
|
|
);
|
|
|
|
|
|
|
|
returnData.push(...executionData);
|
2021-07-19 23:58:54 -07:00
|
|
|
} else if (operation === 'update') {
|
|
|
|
// ----------------------------------
|
|
|
|
// update
|
|
|
|
// ----------------------------------
|
2020-01-28 07:50:15 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
requestMethod = 'PATCH';
|
|
|
|
const id = this.getNodeParameter('id', i) as string;
|
|
|
|
endpoint = `contacts/${id}`;
|
2020-01-28 07:50:15 -08:00
|
|
|
|
2022-11-18 07:29:44 -08:00
|
|
|
const updateFields = this.getNodeParameter('updateFields', i);
|
2021-07-19 23:58:54 -07:00
|
|
|
Object.assign(qs, updateFields);
|
|
|
|
|
2022-08-17 08:50:24 -07:00
|
|
|
const responseData = await harvestApiRequest.call(
|
|
|
|
this,
|
|
|
|
requestMethod,
|
|
|
|
qs,
|
|
|
|
endpoint,
|
|
|
|
body,
|
|
|
|
);
|
2022-08-30 08:55:33 -07:00
|
|
|
|
|
|
|
const executionData = this.helpers.constructExecutionMetaData(
|
|
|
|
this.helpers.returnJsonArray(responseData),
|
|
|
|
{ itemData: { item: i } },
|
|
|
|
);
|
|
|
|
|
|
|
|
returnData.push(...executionData);
|
2021-07-19 23:58:54 -07:00
|
|
|
} else if (operation === 'delete') {
|
|
|
|
// ----------------------------------
|
|
|
|
// delete
|
|
|
|
// ----------------------------------
|
|
|
|
|
|
|
|
requestMethod = 'DELETE';
|
|
|
|
const id = this.getNodeParameter('id', i) as string;
|
|
|
|
endpoint = `contacts/${id}`;
|
|
|
|
|
|
|
|
const responseData = await harvestApiRequest.call(this, requestMethod, qs, endpoint);
|
2022-08-30 08:55:33 -07:00
|
|
|
|
|
|
|
const executionData = this.helpers.constructExecutionMetaData(
|
|
|
|
this.helpers.returnJsonArray(responseData),
|
|
|
|
{ itemData: { item: i } },
|
|
|
|
);
|
|
|
|
|
|
|
|
returnData.push(...executionData);
|
2021-07-19 23:58:54 -07:00
|
|
|
} else {
|
2022-08-17 08:50:24 -07:00
|
|
|
throw new NodeOperationError(
|
|
|
|
this.getNode(),
|
|
|
|
`The resource "${resource}" is not known!`,
|
|
|
|
{ itemIndex: i },
|
|
|
|
);
|
2021-07-19 23:58:54 -07:00
|
|
|
}
|
|
|
|
} else if (resource === 'company') {
|
|
|
|
if (operation === 'get') {
|
|
|
|
// ----------------------------------
|
|
|
|
// get
|
|
|
|
// ----------------------------------
|
|
|
|
|
|
|
|
requestMethod = 'GET';
|
2022-12-29 03:20:43 -08:00
|
|
|
endpoint = 'company';
|
2021-07-19 23:58:54 -07:00
|
|
|
|
|
|
|
const responseData = await harvestApiRequest.call(this, requestMethod, qs, endpoint);
|
2022-08-30 08:55:33 -07:00
|
|
|
|
|
|
|
const executionData = this.helpers.constructExecutionMetaData(
|
|
|
|
this.helpers.returnJsonArray(responseData),
|
|
|
|
{ itemData: { item: i } },
|
|
|
|
);
|
|
|
|
|
|
|
|
returnData.push(...executionData);
|
2021-07-19 23:58:54 -07:00
|
|
|
} else {
|
2022-08-17 08:50:24 -07:00
|
|
|
throw new NodeOperationError(
|
|
|
|
this.getNode(),
|
|
|
|
`The resource "${resource}" is not known!`,
|
|
|
|
{ itemIndex: i },
|
|
|
|
);
|
2021-07-19 23:58:54 -07:00
|
|
|
}
|
|
|
|
} else if (resource === 'task') {
|
|
|
|
if (operation === 'get') {
|
|
|
|
// ----------------------------------
|
|
|
|
// get
|
|
|
|
// ----------------------------------
|
2020-02-03 04:36:51 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
requestMethod = 'GET';
|
|
|
|
const id = this.getNodeParameter('id', i) as string;
|
|
|
|
|
|
|
|
endpoint = `tasks/${id}`;
|
2020-02-03 04:36:51 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
const responseData = await harvestApiRequest.call(this, requestMethod, qs, endpoint);
|
2022-08-30 08:55:33 -07:00
|
|
|
|
|
|
|
const executionData = this.helpers.constructExecutionMetaData(
|
|
|
|
this.helpers.returnJsonArray(responseData),
|
|
|
|
{ itemData: { item: i } },
|
|
|
|
);
|
|
|
|
|
|
|
|
returnData.push(...executionData);
|
2021-07-19 23:58:54 -07:00
|
|
|
} else if (operation === 'getAll') {
|
|
|
|
// ----------------------------------
|
|
|
|
// getAll
|
|
|
|
// ----------------------------------
|
2020-02-03 04:36:51 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
const responseData: IDataObject[] = await getAllResource.call(this, 'tasks', i);
|
2022-08-30 08:55:33 -07:00
|
|
|
|
|
|
|
const executionData = this.helpers.constructExecutionMetaData(
|
|
|
|
this.helpers.returnJsonArray(responseData),
|
|
|
|
{ itemData: { item: i } },
|
|
|
|
);
|
|
|
|
|
|
|
|
returnData.push(...executionData);
|
2021-07-19 23:58:54 -07:00
|
|
|
} else if (operation === 'create') {
|
|
|
|
// ----------------------------------
|
|
|
|
// create
|
|
|
|
// ----------------------------------
|
2020-02-03 04:36:51 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
requestMethod = 'POST';
|
|
|
|
endpoint = 'tasks';
|
2020-02-03 04:36:51 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
body.name = this.getNodeParameter('name', i) as string;
|
2020-02-03 04:36:51 -08:00
|
|
|
|
2022-11-18 07:29:44 -08:00
|
|
|
const additionalFields = this.getNodeParameter('additionalFields', i);
|
2021-07-19 23:58:54 -07:00
|
|
|
Object.assign(body, additionalFields);
|
2020-02-03 04:36:51 -08:00
|
|
|
|
2022-08-17 08:50:24 -07:00
|
|
|
const responseData = await harvestApiRequest.call(
|
|
|
|
this,
|
|
|
|
requestMethod,
|
|
|
|
qs,
|
|
|
|
endpoint,
|
|
|
|
body,
|
|
|
|
);
|
2022-08-30 08:55:33 -07:00
|
|
|
|
|
|
|
const executionData = this.helpers.constructExecutionMetaData(
|
|
|
|
this.helpers.returnJsonArray(responseData),
|
|
|
|
{ itemData: { item: i } },
|
|
|
|
);
|
|
|
|
|
|
|
|
returnData.push(...executionData);
|
2021-07-19 23:58:54 -07:00
|
|
|
} else if (operation === 'update') {
|
|
|
|
// ----------------------------------
|
|
|
|
// update
|
|
|
|
// ----------------------------------
|
2020-01-31 04:47:20 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
requestMethod = 'PATCH';
|
|
|
|
const id = this.getNodeParameter('id', i) as string;
|
|
|
|
endpoint = `tasks/${id}`;
|
2020-01-31 04:47:20 -08:00
|
|
|
|
2022-11-18 07:29:44 -08:00
|
|
|
const updateFields = this.getNodeParameter('updateFields', i);
|
2021-07-19 23:58:54 -07:00
|
|
|
Object.assign(qs, updateFields);
|
2020-01-28 07:50:15 -08:00
|
|
|
|
2022-08-17 08:50:24 -07:00
|
|
|
const responseData = await harvestApiRequest.call(
|
|
|
|
this,
|
|
|
|
requestMethod,
|
|
|
|
qs,
|
|
|
|
endpoint,
|
|
|
|
body,
|
|
|
|
);
|
2022-08-30 08:55:33 -07:00
|
|
|
|
|
|
|
const executionData = this.helpers.constructExecutionMetaData(
|
|
|
|
this.helpers.returnJsonArray(responseData),
|
|
|
|
{ itemData: { item: i } },
|
|
|
|
);
|
|
|
|
|
|
|
|
returnData.push(...executionData);
|
2021-07-19 23:58:54 -07:00
|
|
|
} else if (operation === 'delete') {
|
|
|
|
// ----------------------------------
|
|
|
|
// delete
|
|
|
|
// ----------------------------------
|
|
|
|
|
|
|
|
requestMethod = 'DELETE';
|
|
|
|
const id = this.getNodeParameter('id', i) as string;
|
|
|
|
endpoint = `tasks/${id}`;
|
|
|
|
|
|
|
|
const responseData = await harvestApiRequest.call(this, requestMethod, qs, endpoint);
|
2022-08-30 08:55:33 -07:00
|
|
|
|
|
|
|
const executionData = this.helpers.constructExecutionMetaData(
|
|
|
|
this.helpers.returnJsonArray(responseData),
|
|
|
|
{ itemData: { item: i } },
|
|
|
|
);
|
|
|
|
|
|
|
|
returnData.push(...executionData);
|
2021-07-19 23:58:54 -07:00
|
|
|
} else {
|
2022-08-17 08:50:24 -07:00
|
|
|
throw new NodeOperationError(
|
|
|
|
this.getNode(),
|
|
|
|
`The resource "${resource}" is not known!`,
|
|
|
|
{ itemIndex: i },
|
|
|
|
);
|
2021-07-19 23:58:54 -07:00
|
|
|
}
|
|
|
|
} else if (resource === 'invoice') {
|
|
|
|
if (operation === 'get') {
|
|
|
|
// ----------------------------------
|
|
|
|
// get
|
|
|
|
// ----------------------------------
|
|
|
|
|
|
|
|
requestMethod = 'GET';
|
|
|
|
const id = this.getNodeParameter('id', i) as string;
|
2020-01-28 07:50:15 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
endpoint = `invoices/${id}`;
|
|
|
|
|
|
|
|
const responseData = await harvestApiRequest.call(this, requestMethod, qs, endpoint);
|
2022-08-30 08:55:33 -07:00
|
|
|
|
|
|
|
const executionData = this.helpers.constructExecutionMetaData(
|
|
|
|
this.helpers.returnJsonArray(responseData),
|
|
|
|
{ itemData: { item: i } },
|
|
|
|
);
|
|
|
|
|
|
|
|
returnData.push(...executionData);
|
2021-07-19 23:58:54 -07:00
|
|
|
} else if (operation === 'getAll') {
|
|
|
|
// ----------------------------------
|
|
|
|
// getAll
|
|
|
|
// ----------------------------------
|
2020-01-28 07:50:15 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
const responseData: IDataObject[] = await getAllResource.call(this, 'invoices', i);
|
2022-08-30 08:55:33 -07:00
|
|
|
|
|
|
|
const executionData = this.helpers.constructExecutionMetaData(
|
|
|
|
this.helpers.returnJsonArray(responseData),
|
|
|
|
{ itemData: { item: i } },
|
|
|
|
);
|
|
|
|
|
|
|
|
returnData.push(...executionData);
|
2021-07-19 23:58:54 -07:00
|
|
|
} else if (operation === 'create') {
|
|
|
|
// ----------------------------------
|
|
|
|
// create
|
|
|
|
// ----------------------------------
|
2020-01-28 07:50:15 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
requestMethod = 'POST';
|
|
|
|
endpoint = 'invoices';
|
2020-01-28 07:50:15 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
body.client_id = this.getNodeParameter('clientId', i) as string;
|
2020-01-28 07:50:15 -08:00
|
|
|
|
2022-11-18 07:29:44 -08:00
|
|
|
const additionalFields = this.getNodeParameter('additionalFields', i);
|
2021-07-19 23:58:54 -07:00
|
|
|
Object.assign(body, additionalFields);
|
2020-01-28 07:50:15 -08:00
|
|
|
|
2022-08-17 08:50:24 -07:00
|
|
|
const responseData = await harvestApiRequest.call(
|
|
|
|
this,
|
|
|
|
requestMethod,
|
|
|
|
qs,
|
|
|
|
endpoint,
|
|
|
|
body,
|
|
|
|
);
|
2022-08-30 08:55:33 -07:00
|
|
|
|
|
|
|
const executionData = this.helpers.constructExecutionMetaData(
|
|
|
|
this.helpers.returnJsonArray(responseData),
|
|
|
|
{ itemData: { item: i } },
|
|
|
|
);
|
|
|
|
|
|
|
|
returnData.push(...executionData);
|
2021-07-19 23:58:54 -07:00
|
|
|
} else if (operation === 'update') {
|
|
|
|
// ----------------------------------
|
|
|
|
// update
|
|
|
|
// ----------------------------------
|
2021-04-02 08:56:45 -07:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
requestMethod = 'PATCH';
|
|
|
|
const id = this.getNodeParameter('id', i) as string;
|
|
|
|
endpoint = `invoices/${id}`;
|
2021-04-02 08:56:45 -07:00
|
|
|
|
2022-11-18 07:29:44 -08:00
|
|
|
const updateFields = this.getNodeParameter('updateFields', i);
|
2021-07-19 23:58:54 -07:00
|
|
|
Object.assign(qs, updateFields);
|
2021-04-02 08:56:45 -07:00
|
|
|
|
2022-08-17 08:50:24 -07:00
|
|
|
const responseData = await harvestApiRequest.call(
|
|
|
|
this,
|
|
|
|
requestMethod,
|
|
|
|
qs,
|
|
|
|
endpoint,
|
|
|
|
body,
|
|
|
|
);
|
2022-08-30 08:55:33 -07:00
|
|
|
|
|
|
|
const executionData = this.helpers.constructExecutionMetaData(
|
|
|
|
this.helpers.returnJsonArray(responseData),
|
|
|
|
{ itemData: { item: i } },
|
|
|
|
);
|
|
|
|
|
|
|
|
returnData.push(...executionData);
|
2021-07-19 23:58:54 -07:00
|
|
|
} else if (operation === 'delete') {
|
|
|
|
// ----------------------------------
|
|
|
|
// delete
|
|
|
|
// ----------------------------------
|
2021-04-02 08:56:45 -07:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
requestMethod = 'DELETE';
|
|
|
|
const id = this.getNodeParameter('id', i) as string;
|
|
|
|
endpoint = `invoices/${id}`;
|
2021-04-02 08:56:45 -07:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
const responseData = await harvestApiRequest.call(this, requestMethod, qs, endpoint);
|
2022-08-30 08:55:33 -07:00
|
|
|
|
|
|
|
const executionData = this.helpers.constructExecutionMetaData(
|
|
|
|
this.helpers.returnJsonArray(responseData),
|
|
|
|
{ itemData: { item: i } },
|
|
|
|
);
|
|
|
|
|
|
|
|
returnData.push(...executionData);
|
2021-07-19 23:58:54 -07:00
|
|
|
} else {
|
2022-08-17 08:50:24 -07:00
|
|
|
throw new NodeOperationError(
|
|
|
|
this.getNode(),
|
|
|
|
`The resource "${resource}" is not known!`,
|
|
|
|
{ itemIndex: i },
|
|
|
|
);
|
2021-07-19 23:58:54 -07:00
|
|
|
}
|
|
|
|
} else if (resource === 'expense') {
|
|
|
|
if (operation === 'get') {
|
|
|
|
// ----------------------------------
|
|
|
|
// get
|
|
|
|
// ----------------------------------
|
2021-04-02 08:56:45 -07:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
requestMethod = 'GET';
|
|
|
|
const id = this.getNodeParameter('id', i) as string;
|
2021-04-02 08:56:45 -07:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
endpoint = `expenses/${id}`;
|
2020-01-31 04:47:20 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
const responseData = await harvestApiRequest.call(this, requestMethod, qs, endpoint);
|
2022-08-30 08:55:33 -07:00
|
|
|
|
|
|
|
const executionData = this.helpers.constructExecutionMetaData(
|
|
|
|
this.helpers.returnJsonArray(responseData),
|
|
|
|
{ itemData: { item: i } },
|
|
|
|
);
|
|
|
|
|
|
|
|
returnData.push(...executionData);
|
2021-07-19 23:58:54 -07:00
|
|
|
} else if (operation === 'getAll') {
|
|
|
|
// ----------------------------------
|
|
|
|
// getAll
|
|
|
|
// ----------------------------------
|
2020-01-28 07:50:15 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
const responseData: IDataObject[] = await getAllResource.call(this, 'expenses', i);
|
2022-08-30 08:55:33 -07:00
|
|
|
|
|
|
|
const executionData = this.helpers.constructExecutionMetaData(
|
|
|
|
this.helpers.returnJsonArray(responseData),
|
|
|
|
{ itemData: { item: i } },
|
|
|
|
);
|
|
|
|
|
|
|
|
returnData.push(...executionData);
|
2021-07-19 23:58:54 -07:00
|
|
|
} else if (operation === 'create') {
|
|
|
|
// ----------------------------------
|
|
|
|
// create
|
|
|
|
// ----------------------------------
|
2020-01-28 07:50:15 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
requestMethod = 'POST';
|
|
|
|
endpoint = 'expenses';
|
2020-01-28 07:50:15 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
body.project_id = this.getNodeParameter('projectId', i) as string;
|
|
|
|
body.expense_category_id = this.getNodeParameter('expenseCategoryId', i) as string;
|
|
|
|
body.spent_date = this.getNodeParameter('spentDate', i) as string;
|
2020-01-28 07:50:15 -08:00
|
|
|
|
2022-11-18 07:29:44 -08:00
|
|
|
const additionalFields = this.getNodeParameter('additionalFields', i);
|
2021-07-19 23:58:54 -07:00
|
|
|
Object.assign(body, additionalFields);
|
2020-01-28 07:50:15 -08:00
|
|
|
|
2022-08-17 08:50:24 -07:00
|
|
|
const responseData = await harvestApiRequest.call(
|
|
|
|
this,
|
|
|
|
requestMethod,
|
|
|
|
qs,
|
|
|
|
endpoint,
|
|
|
|
body,
|
|
|
|
);
|
2022-08-30 08:55:33 -07:00
|
|
|
|
|
|
|
const executionData = this.helpers.constructExecutionMetaData(
|
|
|
|
this.helpers.returnJsonArray(responseData),
|
|
|
|
{ itemData: { item: i } },
|
|
|
|
);
|
|
|
|
|
|
|
|
returnData.push(...executionData);
|
2021-07-19 23:58:54 -07:00
|
|
|
} else if (operation === 'update') {
|
|
|
|
// ----------------------------------
|
|
|
|
// update
|
|
|
|
// ----------------------------------
|
2020-01-31 06:06:10 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
requestMethod = 'PATCH';
|
|
|
|
const id = this.getNodeParameter('id', i) as string;
|
|
|
|
endpoint = `expenses/${id}`;
|
2020-01-31 06:06:10 -08:00
|
|
|
|
2022-11-18 07:29:44 -08:00
|
|
|
const updateFields = this.getNodeParameter('updateFields', i);
|
2021-07-19 23:58:54 -07:00
|
|
|
Object.assign(qs, updateFields);
|
2020-01-31 06:06:10 -08:00
|
|
|
|
2022-08-17 08:50:24 -07:00
|
|
|
const responseData = await harvestApiRequest.call(
|
|
|
|
this,
|
|
|
|
requestMethod,
|
|
|
|
qs,
|
|
|
|
endpoint,
|
|
|
|
body,
|
|
|
|
);
|
2022-08-30 08:55:33 -07:00
|
|
|
|
|
|
|
const executionData = this.helpers.constructExecutionMetaData(
|
|
|
|
this.helpers.returnJsonArray(responseData),
|
|
|
|
{ itemData: { item: i } },
|
|
|
|
);
|
|
|
|
|
|
|
|
returnData.push(...executionData);
|
2021-07-19 23:58:54 -07:00
|
|
|
} else if (operation === 'delete') {
|
|
|
|
// ----------------------------------
|
|
|
|
// delete
|
|
|
|
// ----------------------------------
|
2020-01-31 06:06:10 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
requestMethod = 'DELETE';
|
|
|
|
const id = this.getNodeParameter('id', i) as string;
|
|
|
|
endpoint = `expenses/${id}`;
|
2020-01-31 06:06:10 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
const responseData = await harvestApiRequest.call(this, requestMethod, qs, endpoint);
|
2022-08-30 08:55:33 -07:00
|
|
|
|
|
|
|
const executionData = this.helpers.constructExecutionMetaData(
|
|
|
|
this.helpers.returnJsonArray(responseData),
|
|
|
|
{ itemData: { item: i } },
|
|
|
|
);
|
|
|
|
|
|
|
|
returnData.push(...executionData);
|
2021-07-19 23:58:54 -07:00
|
|
|
} else {
|
2022-08-17 08:50:24 -07:00
|
|
|
throw new NodeOperationError(
|
|
|
|
this.getNode(),
|
|
|
|
`The resource "${resource}" is not known!`,
|
|
|
|
{ itemIndex: i },
|
|
|
|
);
|
2021-07-19 23:58:54 -07:00
|
|
|
}
|
|
|
|
} else if (resource === 'estimate') {
|
|
|
|
if (operation === 'get') {
|
|
|
|
// ----------------------------------
|
|
|
|
// get
|
|
|
|
// ----------------------------------
|
2020-01-31 06:06:10 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
requestMethod = 'GET';
|
|
|
|
const id = this.getNodeParameter('id', i) as string;
|
2020-01-31 06:06:10 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
endpoint = `estimates/${id}`;
|
2020-01-31 04:47:20 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
const responseData = await harvestApiRequest.call(this, requestMethod, qs, endpoint);
|
2022-08-30 08:55:33 -07:00
|
|
|
|
|
|
|
const executionData = this.helpers.constructExecutionMetaData(
|
|
|
|
this.helpers.returnJsonArray(responseData),
|
|
|
|
{ itemData: { item: i } },
|
|
|
|
);
|
|
|
|
|
|
|
|
returnData.push(...executionData);
|
2021-07-19 23:58:54 -07:00
|
|
|
} else if (operation === 'getAll') {
|
|
|
|
// ----------------------------------
|
|
|
|
// getAll
|
|
|
|
// ----------------------------------
|
|
|
|
|
|
|
|
const responseData: IDataObject[] = await getAllResource.call(this, 'estimates', i);
|
2022-08-30 08:55:33 -07:00
|
|
|
|
|
|
|
const executionData = this.helpers.constructExecutionMetaData(
|
|
|
|
this.helpers.returnJsonArray(responseData),
|
|
|
|
{ itemData: { item: i } },
|
|
|
|
);
|
|
|
|
|
|
|
|
returnData.push(...executionData);
|
2021-07-19 23:58:54 -07:00
|
|
|
} else if (operation === 'create') {
|
|
|
|
// ----------------------------------
|
|
|
|
// create
|
|
|
|
// ----------------------------------
|
|
|
|
|
|
|
|
requestMethod = 'POST';
|
|
|
|
endpoint = 'estimates';
|
2020-01-28 07:50:15 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
body.client_id = this.getNodeParameter('clientId', i) as string;
|
2020-01-28 07:50:15 -08:00
|
|
|
|
2022-11-18 07:29:44 -08:00
|
|
|
const additionalFields = this.getNodeParameter('additionalFields', i);
|
2021-07-19 23:58:54 -07:00
|
|
|
Object.assign(body, additionalFields);
|
2020-01-28 07:50:15 -08:00
|
|
|
|
2022-08-17 08:50:24 -07:00
|
|
|
const responseData = await harvestApiRequest.call(
|
|
|
|
this,
|
|
|
|
requestMethod,
|
|
|
|
qs,
|
|
|
|
endpoint,
|
|
|
|
body,
|
|
|
|
);
|
2022-08-30 08:55:33 -07:00
|
|
|
|
|
|
|
const executionData = this.helpers.constructExecutionMetaData(
|
|
|
|
this.helpers.returnJsonArray(responseData),
|
|
|
|
{ itemData: { item: i } },
|
|
|
|
);
|
|
|
|
|
|
|
|
returnData.push(...executionData);
|
2021-07-19 23:58:54 -07:00
|
|
|
} else if (operation === 'update') {
|
|
|
|
// ----------------------------------
|
|
|
|
// update
|
|
|
|
// ----------------------------------
|
2020-01-28 23:04:52 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
requestMethod = 'PATCH';
|
|
|
|
const id = this.getNodeParameter('id', i) as string;
|
|
|
|
endpoint = `estimates/${id}`;
|
2020-02-03 03:57:39 -08:00
|
|
|
|
2022-11-18 07:29:44 -08:00
|
|
|
const updateFields = this.getNodeParameter('updateFields', i);
|
2021-07-19 23:58:54 -07:00
|
|
|
Object.assign(qs, updateFields);
|
2020-02-03 03:57:39 -08:00
|
|
|
|
2022-08-17 08:50:24 -07:00
|
|
|
const responseData = await harvestApiRequest.call(
|
|
|
|
this,
|
|
|
|
requestMethod,
|
|
|
|
qs,
|
|
|
|
endpoint,
|
|
|
|
body,
|
|
|
|
);
|
2022-08-30 08:55:33 -07:00
|
|
|
|
|
|
|
const executionData = this.helpers.constructExecutionMetaData(
|
|
|
|
this.helpers.returnJsonArray(responseData),
|
|
|
|
{ itemData: { item: i } },
|
|
|
|
);
|
|
|
|
|
|
|
|
returnData.push(...executionData);
|
2021-07-19 23:58:54 -07:00
|
|
|
} else if (operation === 'delete') {
|
|
|
|
// ----------------------------------
|
|
|
|
// delete
|
|
|
|
// ----------------------------------
|
2020-02-03 03:57:39 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
requestMethod = 'DELETE';
|
|
|
|
const id = this.getNodeParameter('id', i) as string;
|
|
|
|
endpoint = `estimates/${id}`;
|
2020-02-03 03:57:39 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
const responseData = await harvestApiRequest.call(this, requestMethod, qs, endpoint);
|
2022-08-30 08:55:33 -07:00
|
|
|
|
|
|
|
const executionData = this.helpers.constructExecutionMetaData(
|
|
|
|
this.helpers.returnJsonArray(responseData),
|
|
|
|
{ itemData: { item: i } },
|
|
|
|
);
|
|
|
|
|
|
|
|
returnData.push(...executionData);
|
2021-07-19 23:58:54 -07:00
|
|
|
} else {
|
2022-08-17 08:50:24 -07:00
|
|
|
throw new NodeOperationError(
|
|
|
|
this.getNode(),
|
|
|
|
`The resource "${resource}" is not known!`,
|
|
|
|
{ itemIndex: i },
|
|
|
|
);
|
2021-07-19 23:58:54 -07:00
|
|
|
}
|
2020-02-03 04:36:51 -08:00
|
|
|
} else {
|
2022-08-17 08:50:24 -07:00
|
|
|
throw new NodeOperationError(this.getNode(), `The resource "${resource}" is not known!`, {
|
|
|
|
itemIndex: i,
|
|
|
|
});
|
2020-01-28 23:04:52 -08:00
|
|
|
}
|
2021-07-19 23:58:54 -07:00
|
|
|
} catch (error) {
|
|
|
|
if (this.continueOnFail()) {
|
2022-08-30 08:55:33 -07:00
|
|
|
const executionErrorData = this.helpers.constructExecutionMetaData(
|
|
|
|
this.helpers.returnJsonArray({ error: error.message }),
|
|
|
|
{ itemData: { item: i } },
|
|
|
|
);
|
|
|
|
|
|
|
|
returnData.push(...executionErrorData);
|
2021-07-19 23:58:54 -07:00
|
|
|
continue;
|
2020-01-28 07:50:15 -08:00
|
|
|
}
|
2021-07-19 23:58:54 -07:00
|
|
|
throw error;
|
2020-01-28 06:46:38 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-08-30 08:55:33 -07:00
|
|
|
return this.prepareOutputData(returnData);
|
2020-01-28 06:46:38 -08:00
|
|
|
}
|
|
|
|
}
|