From 0121e3b85cb26ea1ad232651a31d3e32ce9ee8fd Mon Sep 17 00:00:00 2001 From: trojanh Date: Mon, 3 Feb 2020 14:53:58 +0530 Subject: [PATCH] Add Create and Update for Invoice API --- .../nodes-base/nodes/Harvest/Harvest.node.ts | 17 +- .../nodes/Harvest/InvoiceDescription.ts | 250 +++++++++++++++++- .../nodes/Harvest/ProjectDescription.ts | 5 +- 3 files changed, 268 insertions(+), 4 deletions(-) diff --git a/packages/nodes-base/nodes/Harvest/Harvest.node.ts b/packages/nodes-base/nodes/Harvest/Harvest.node.ts index 8ea4b6d339..ebe61d38ab 100644 --- a/packages/nodes-base/nodes/Harvest/Harvest.node.ts +++ b/packages/nodes-base/nodes/Harvest/Harvest.node.ts @@ -362,6 +362,21 @@ export class Harvest implements INodeType { const responseData = await harvestApiRequest.call(this, requestMethod, qs, endpoint, body); returnData.push(responseData); + } else if (operation === 'update') { + // ---------------------------------- + // update + // ---------------------------------- + + requestMethod = 'PATCH'; + const id = this.getNodeParameter('id', i) as string; + endpoint = `${resource}/${id}`; + + const updateFields = this.getNodeParameter('updateFields', i) as IDataObject; + + Object.assign(body, updateFields); + const responseData = await harvestApiRequest.call(this, requestMethod, qs, endpoint, body); + returnData.push(responseData); + } else if (operation === 'delete') { // ---------------------------------- // delete @@ -574,7 +589,7 @@ export class Harvest implements INodeType { requestMethod = 'POST'; endpoint = resource; - body.name = this.getNodeParameter('name', i) as string; + body.client_id = this.getNodeParameter('client_id', i) as string; const additionalFields = this.getNodeParameter('additionalFields', i) as IDataObject; Object.assign(body, additionalFields); diff --git a/packages/nodes-base/nodes/Harvest/InvoiceDescription.ts b/packages/nodes-base/nodes/Harvest/InvoiceDescription.ts index 8ec5814dff..f294653fb2 100644 --- a/packages/nodes-base/nodes/Harvest/InvoiceDescription.ts +++ b/packages/nodes-base/nodes/Harvest/InvoiceDescription.ts @@ -204,6 +204,254 @@ export const invoiceFields = [ }, }, description: 'The ID of the invoice want to delete.', -} +}, + /* -------------------------------------------------------------------------- */ + /* invoice:create */ + /* -------------------------------------------------------------------------- */ + { + displayName: 'client_id', + name: 'client_id', + type: 'string', + displayOptions: { + show: { + operation: [ + 'create', + ], + resource, + }, + }, + default: '', + required: true, + description: 'The ID of the retainer associated with this invoice..', + }, + { + displayName: 'Additional Fields', + name: 'additionalFields', + type: 'collection', + placeholder: 'Add Field', + displayOptions: { + show: { + operation: [ + 'create', + ], + resource, + }, + }, + default: {}, + options: [ + { + displayName: 'Retainer Id', + name: 'retainer_id', + type: 'boolean', + default: true, + description: 'The ID of the retainer associated with this invoice.' + }, + { + displayName: 'Estimate Id', + name: 'estimate_id', + type: 'string', + default: '', + description: 'The ID of the estimate associated with this invoice.' + }, + { + displayName: 'Number', + name: 'number', + type: 'string', + default: '', + description: 'If no value is set, the number will be automatically generated.' + }, + { + displayName: 'Purchase Order', + name: 'purchase_order', + type: 'string', + default: '', + description: 'The purchase order number.' + }, + { + displayName: 'Tax', + name: 'tax', + type: 'string', + default: '', + description: 'This percentage is applied to the subtotal, including line items and discounts. Example: use 10.0 for 10.0%.' + }, + { + displayName: 'Tax2', + name: 'tax2', + type: 'string', + default: '', + description: 'This percentage is applied to the subtotal, including line items and discounts. Example: use 10.0 for 10.0%.' + }, + { + displayName: 'Discount', + name: 'over_budget_notification_percentage', + type: 'string', + default: '', + description: 'This percentage is subtracted from the subtotal. Example: use 10.0 for 10.0%.' + }, + { + displayName: 'Subject', + name: 'subject', + type: 'string', + default: '', + description: 'The invoice subject.' + }, + { + displayName: 'Currency', + name: 'currency', + type: 'string', + default: '', + description: 'The currency used by the invoice. If not provided, the client’s currency will be used. See a list of supported currencies' + }, + { + displayName: 'Payment Term', + name: 'payment_term', + type: 'string', + default: '', + description: 'The timeframe in which the invoice should be paid. Defaults to custom. Options: upon receipt, net 15, net 30, net 45, or net 60.' + }, + { + displayName: 'Notes', + name: 'notes', + type: 'string', + default: '', + description: 'Notes about the project.' + }, + { + displayName: 'Issue Date', + name: 'issue_date', + type: 'dateTime', + default: '', + description: 'Date the invoice was issued. Defaults to today’s date.' + }, + { + displayName: 'Due Date', + name: 'ends_on', + type: 'dateTime', + default: '', + description: 'Date the invoice is due. Defaults to the issue_date if no payment_term is specified.' + }, + + ], + }, + + /* -------------------------------------------------------------------------- */ + /* invoice:update */ + /* -------------------------------------------------------------------------- */ + { + displayName: 'Update Fields', + name: 'updateFields', + type: 'collection', + placeholder: 'Add Field', + displayOptions: { + show: { + operation: [ + 'create', + ], + resource, + }, + }, + default: {}, + options: [ + { + displayName: 'client_id', + name: 'client_id', + type: 'string', + default: '', + description: 'The ID of the retainer associated with this invoice..', + }, + { + displayName: 'Retainer Id', + name: 'retainer_id', + type: 'boolean', + default: true, + description: 'The ID of the retainer associated with this invoice.' + }, + { + displayName: 'Estimate Id', + name: 'estimate_id', + type: 'string', + default: '', + description: 'The ID of the estimate associated with this invoice.' + }, + { + displayName: 'Number', + name: 'number', + type: 'string', + default: '', + description: 'If no value is set, the number will be automatically generated.' + }, + { + displayName: 'Purchase Order', + name: 'purchase_order', + type: 'string', + default: '', + description: 'The purchase order number.' + }, + { + displayName: 'Tax', + name: 'tax', + type: 'string', + default: '', + description: 'This percentage is applied to the subtotal, including line items and discounts. Example: use 10.0 for 10.0%.' + }, + { + displayName: 'Tax2', + name: 'tax2', + type: 'string', + default: '', + description: 'This percentage is applied to the subtotal, including line items and discounts. Example: use 10.0 for 10.0%.' + }, + { + displayName: 'Discount', + name: 'over_budget_notification_percentage', + type: 'string', + default: '', + description: 'This percentage is subtracted from the subtotal. Example: use 10.0 for 10.0%.' + }, + { + displayName: 'Subject', + name: 'subject', + type: 'string', + default: '', + description: 'The invoice subject.' + }, + { + displayName: 'Currency', + name: 'currency', + type: 'string', + default: '', + description: 'The currency used by the invoice. If not provided, the client’s currency will be used. See a list of supported currencies' + }, + { + displayName: 'Payment Term', + name: 'payment_term', + type: 'string', + default: '', + description: 'The timeframe in which the invoice should be paid. Defaults to custom. Options: upon receipt, net 15, net 30, net 45, or net 60.' + }, + { + displayName: 'Notes', + name: 'notes', + type: 'string', + default: '', + description: 'Notes about the project.' + }, + { + displayName: 'Issue Date', + name: 'issue_date', + type: 'dateTime', + default: '', + description: 'Date the invoice was issued. Defaults to today’s date.' + }, + { + displayName: 'Due Date', + name: 'ends_on', + type: 'dateTime', + default: '', + description: 'Date the invoice is due. Defaults to the issue_date if no payment_term is specified.' + }, + + ], + }, ] as INodeProperties[]; diff --git a/packages/nodes-base/nodes/Harvest/ProjectDescription.ts b/packages/nodes-base/nodes/Harvest/ProjectDescription.ts index 839c1aafdc..d2092b4276 100644 --- a/packages/nodes-base/nodes/Harvest/ProjectDescription.ts +++ b/packages/nodes-base/nodes/Harvest/ProjectDescription.ts @@ -383,8 +383,8 @@ export const projectFields = [ /* -------------------------------------------------------------------------- */ { - displayName: 'Additional Fields', - name: 'additionalFields', + displayName: 'Update Fields', + name: 'updateFields', type: 'collection', placeholder: 'Add Field', displayOptions: { @@ -535,3 +535,4 @@ export const projectFields = [ }, ] as INodeProperties[]; +