From da450dcb41c5085a0202f94e7bcc25b7dff9b2ad Mon Sep 17 00:00:00 2001 From: Ricardo Espinoza Date: Mon, 7 Dec 2020 17:44:10 -0500 Subject: [PATCH] :zap: Add label field to persons, organizations and deals (#1209) * :zap: Add label field to persons, organizations and deals * :zap: Add option no label to label field * :zap: Add organization:update operation * :zap: Fix removing label from Organization on Pipedrive-Node Co-authored-by: Jan Oberhauser --- .../nodes/Pipedrive/GenericFunctions.ts | 1 - .../nodes/Pipedrive/Pipedrive.node.ts | 572 +++++++++++++----- 2 files changed, 416 insertions(+), 157 deletions(-) diff --git a/packages/nodes-base/nodes/Pipedrive/GenericFunctions.ts b/packages/nodes-base/nodes/Pipedrive/GenericFunctions.ts index 9122baf019472..408a32b8fe2e9 100644 --- a/packages/nodes-base/nodes/Pipedrive/GenericFunctions.ts +++ b/packages/nodes-base/nodes/Pipedrive/GenericFunctions.ts @@ -75,7 +75,6 @@ export async function pipedriveApiRequest(this: IHookFunctions | IExecuteFunctio } query.api_token = credentials.apiToken; - //@ts-ignore responseData = await this.helpers.request(options); diff --git a/packages/nodes-base/nodes/Pipedrive/Pipedrive.node.ts b/packages/nodes-base/nodes/Pipedrive/Pipedrive.node.ts index e18f0448cb764..c9aeda94ce34f 100644 --- a/packages/nodes-base/nodes/Pipedrive/Pipedrive.node.ts +++ b/packages/nodes-base/nodes/Pipedrive/Pipedrive.node.ts @@ -353,12 +353,11 @@ export class Pipedrive implements INodeType { value: 'getAll', description: 'Get data of all organizations', }, - // TODO: Currently missing - // { - // name: 'Update', - // value: 'update', - // description: 'Update an organization', - // }, + { + name: 'Update', + value: 'update', + description: 'Update an organization', + }, ], default: 'create', description: 'The operation to perform.', @@ -840,6 +839,48 @@ export class Pipedrive implements INodeType { default: 'USD', description: 'Currency of the deal. Accepts a 3-character currency code. Like EUR, USD, ...', }, + { + displayName: 'Custom Properties', + name: 'customProperties', + placeholder: 'Add Custom Property', + description: 'Adds a custom property to set also values which have not been predefined.', + type: 'fixedCollection', + typeOptions: { + multipleValues: true, + }, + default: {}, + options: [ + { + name: 'property', + displayName: 'Property', + values: [ + { + displayName: 'Property Name', + name: 'name', + type: 'string', + default: '', + description: 'Name of the property to set.', + }, + { + displayName: 'Property Value', + name: 'value', + type: 'string', + default: '', + description: 'Value of the property to set.', + }, + ], + }, + ], + }, + { + displayName: 'Label', + name: 'label', + type: 'options', + typeOptions: { + loadOptionsMethod: 'getDealLabels', + }, + default: '', + }, { displayName: 'Lost Reason', name: 'lost_reason', @@ -935,39 +976,6 @@ export class Pipedrive implements INodeType { default: '3', description: 'Visibility of the deal. If omitted, visibility will be set to the default visibility setting of this item type for the authorized user.', }, - { - displayName: 'Custom Properties', - name: 'customProperties', - placeholder: 'Add Custom Property', - description: 'Adds a custom property to set also values which have not been predefined.', - type: 'fixedCollection', - typeOptions: { - multipleValues: true, - }, - default: {}, - options: [ - { - name: 'property', - displayName: 'Property', - values: [ - { - displayName: 'Property Name', - name: 'name', - type: 'string', - default: '', - description: 'Name of the property to set.', - }, - { - displayName: 'Property Value', - name: 'value', - type: 'string', - default: '', - description: 'Value of the property to set.', - }, - ], - }, - ], - }, ], }, @@ -1082,6 +1090,48 @@ export class Pipedrive implements INodeType { default: 'USD', description: 'Currency of the deal. Accepts a 3-character currency code. Like EUR, USD, ...', }, + { + displayName: 'Custom Properties', + name: 'customProperties', + placeholder: 'Add Custom Property', + description: 'Adds a custom property to set also values which have not been predefined.', + type: 'fixedCollection', + typeOptions: { + multipleValues: true, + }, + default: {}, + options: [ + { + name: 'property', + displayName: 'Property', + values: [ + { + displayName: 'Property Name', + name: 'name', + type: 'string', + default: '', + description: 'Name of the property to set.', + }, + { + displayName: 'Property Value', + name: 'value', + type: 'string', + default: '', + description: 'Value of the property to set.', + }, + ], + }, + ], + }, + { + displayName: 'Label', + name: 'label', + type: 'options', + typeOptions: { + loadOptionsMethod: 'getDealLabels', + }, + default: '', + }, { displayName: 'Lost Reason', name: 'lost_reason', @@ -1177,39 +1227,6 @@ export class Pipedrive implements INodeType { default: '3', description: 'Visibility of the deal. If omitted, visibility will be set to the default visibility setting of this item type for the authorized user.', }, - { - displayName: 'Custom Properties', - name: 'customProperties', - placeholder: 'Add Custom Property', - description: 'Adds a custom property to set also values which have not been predefined.', - type: 'fixedCollection', - typeOptions: { - multipleValues: true, - }, - default: {}, - options: [ - { - name: 'property', - displayName: 'Property', - values: [ - { - displayName: 'Property Name', - name: 'name', - type: 'string', - default: '', - description: 'Name of the property to set.', - }, - { - displayName: 'Property Value', - name: 'value', - type: 'string', - default: '', - description: 'Value of the property to set.', - }, - ], - }, - ], - }, ], }, @@ -1613,23 +1630,6 @@ export class Pipedrive implements INodeType { }, default: {}, options: [ - { - displayName: 'Visible to', - name: 'visible_to', - type: 'options', - options: [ - { - name: 'Owner & followers (private)', - value: '1', - }, - { - name: 'Entire company (shared)', - value: '3', - }, - ], - default: '3', - description: 'Visibility of the person. If omitted, visibility will be set to the default visibility setting of this item type for the authorized user.', - }, { displayName: 'Custom Properties', name: 'customProperties', @@ -1663,6 +1663,32 @@ export class Pipedrive implements INodeType { }, ], }, + { + displayName: 'Label', + name: 'label', + type: 'options', + typeOptions: { + loadOptionsMethod: 'getOrganizationLabels', + }, + default: '', + }, + { + displayName: 'Visible to', + name: 'visible_to', + type: 'options', + options: [ + { + name: 'Owner & followers (private)', + value: '1', + }, + { + name: 'Entire company (shared)', + value: '3', + }, + ], + default: '3', + description: 'Visibility of the person. If omitted, visibility will be set to the default visibility setting of this item type for the authorized user.', + }, ], }, @@ -1710,76 +1736,99 @@ export class Pipedrive implements INodeType { description: 'ID of the organization to get.', }, - - - // ---------------------------------- - // person - // ---------------------------------- - // ---------------------------------- - // person:create + // organization:update // ---------------------------------- { - displayName: 'Name', - name: 'name', - type: 'string', + displayName: 'Organization ID', + name: 'organizationId', + type: 'number', default: '', required: true, displayOptions: { show: { operation: [ - 'create', + 'update', ], resource: [ - 'person', + 'organization', ], }, }, - description: 'The name of the person to create', + description: 'The ID of the organization to create', }, { - displayName: 'Additional Fields', - name: 'additionalFields', + displayName: 'Update Fields', + name: 'updateFields', type: 'collection', placeholder: 'Add Field', displayOptions: { show: { operation: [ - 'create', + 'update', ], resource: [ - 'person', + 'organization', ], }, }, default: {}, options: [ { - displayName: 'Email', - name: 'email', - type: 'string', + displayName: 'Custom Properties', + name: 'customProperties', + placeholder: 'Add Custom Property', + description: 'Adds a custom property to set also values which have not been predefined.', + type: 'fixedCollection', typeOptions: { multipleValues: true, }, - default: '', - description: 'Email of the person.', + default: {}, + options: [ + { + name: 'property', + displayName: 'Property', + values: [ + { + displayName: 'Property Name', + name: 'name', + type: 'string', + default: '', + description: 'Name of the property to set.', + }, + { + displayName: 'Property Value', + name: 'value', + type: 'string', + default: '', + description: 'Value of the property to set.', + }, + ], + }, + ], }, { - displayName: 'Organization ID', - name: 'org_id', - type: 'number', - default: 0, - description: 'ID of the organization this person will belong to.', + displayName: 'Label', + name: 'label', + type: 'options', + typeOptions: { + loadOptionsMethod: 'getOrganizationLabels', + }, + default: '', }, { - displayName: 'Phone', - name: 'phone', + displayName: 'Name', + name: 'name', type: 'string', - typeOptions: { - multipleValues: true, - }, default: '', - description: 'Phone number of the person.', + description: 'Organization name', + }, + { + displayName: 'Owner ID', + name: 'owner_id', + type: 'number', + default: 0, + description: 'The ID of the user who will be marked as the owner of this Organization. When omitted, the authorized User ID will be used.', }, { displayName: 'Visible to', @@ -1798,6 +1847,53 @@ export class Pipedrive implements INodeType { default: '3', description: 'Visibility of the person. If omitted, visibility will be set to the default visibility setting of this item type for the authorized user.', }, + ], + }, + + + + // ---------------------------------- + // person + // ---------------------------------- + + // ---------------------------------- + // person:create + // ---------------------------------- + { + displayName: 'Name', + name: 'name', + type: 'string', + default: '', + required: true, + displayOptions: { + show: { + operation: [ + 'create', + ], + resource: [ + 'person', + ], + }, + }, + description: 'The name of the person to create', + }, + { + displayName: 'Additional Fields', + name: 'additionalFields', + type: 'collection', + placeholder: 'Add Field', + displayOptions: { + show: { + operation: [ + 'create', + ], + resource: [ + 'person', + ], + }, + }, + default: {}, + options: [ { displayName: 'Custom Properties', name: 'customProperties', @@ -1831,6 +1927,59 @@ export class Pipedrive implements INodeType { }, ], }, + { + displayName: 'Email', + name: 'email', + type: 'string', + typeOptions: { + multipleValues: true, + }, + default: '', + description: 'Email of the person.', + }, + { + displayName: 'Label', + name: 'label', + type: 'options', + typeOptions: { + loadOptionsMethod: 'getPersonLabels', + }, + default: '', + }, + { + displayName: 'Organization ID', + name: 'org_id', + type: 'number', + default: 0, + description: 'ID of the organization this person will belong to.', + }, + { + displayName: 'Phone', + name: 'phone', + type: 'string', + typeOptions: { + multipleValues: true, + }, + default: '', + description: 'Phone number of the person.', + }, + { + displayName: 'Visible to', + name: 'visible_to', + type: 'options', + options: [ + { + name: 'Owner & followers (private)', + value: '1', + }, + { + name: 'Entire company (shared)', + value: '3', + }, + ], + default: '3', + description: 'Visibility of the person. If omitted, visibility will be set to the default visibility setting of this item type for the authorized user.', + }, ], }, @@ -1917,6 +2066,39 @@ export class Pipedrive implements INodeType { }, default: {}, options: [ + { + displayName: 'Custom Properties', + name: 'customProperties', + placeholder: 'Add Custom Property', + description: 'Adds a custom property to set also values which have not been predefined.', + type: 'fixedCollection', + typeOptions: { + multipleValues: true, + }, + default: {}, + options: [ + { + name: 'property', + displayName: 'Property', + values: [ + { + displayName: 'Property Name', + name: 'name', + type: 'string', + default: '', + description: 'Name of the property to set.', + }, + { + displayName: 'Property Value', + name: 'value', + type: 'string', + default: '', + description: 'Value of the property to set.', + }, + ], + }, + ], + }, { displayName: 'Email', name: 'email', @@ -1927,6 +2109,15 @@ export class Pipedrive implements INodeType { default: '', description: 'Email of the person.', }, + { + displayName: 'Label', + name: 'label', + type: 'options', + typeOptions: { + loadOptionsMethod: 'getPersonLabels', + }, + default: '', + }, { displayName: 'Name', name: 'name', @@ -1968,39 +2159,6 @@ export class Pipedrive implements INodeType { default: '3', description: 'Visibility of the deal. If omitted, visibility will be set to the default visibility setting of this item type for the authorized user.', }, - { - displayName: 'Custom Properties', - name: 'customProperties', - placeholder: 'Add Custom Property', - description: 'Adds a custom property to set also values which have not been predefined.', - type: 'fixedCollection', - typeOptions: { - multipleValues: true, - }, - default: {}, - options: [ - { - name: 'property', - displayName: 'Property', - values: [ - { - displayName: 'Property Name', - name: 'name', - type: 'string', - default: '', - description: 'Name of the property to set.', - }, - { - displayName: 'Property Value', - name: 'value', - type: 'string', - default: '', - description: 'Value of the property to set.', - }, - ], - }, - ], - }, ], }, @@ -2271,6 +2429,84 @@ export class Pipedrive implements INodeType { } return returnData; }, + // Get all the person labels to display them to user so that he can + // select them easily + async getPersonLabels(this: ILoadOptionsFunctions): Promise { + const returnData: INodePropertyOptions[] = []; + const operation = this.getCurrentNodeParameter('operation') as string; + const { data } = await pipedriveApiRequest.call(this, 'GET', '/personFields', {}); + for (const field of data) { + if (field.key === 'label') { + if (field.options) { + for (const option of field.options) { + returnData.push({ + name: option.label, + value: option.id, + }); + } + } + } + } + if (operation === 'update') { + returnData.push({ + name: 'No Label', + value: 'null', + }); + } + return returnData; + }, + // Get all the labels to display them to user so that he can + // select them easily + async getOrganizationLabels(this: ILoadOptionsFunctions): Promise { + const returnData: INodePropertyOptions[] = []; + const operation = this.getCurrentNodeParameter('operation') as string; + const { data } = await pipedriveApiRequest.call(this, 'GET', '/organizationFields', {}); + for (const field of data) { + if (field.key === 'label') { + if (field.options) { + for (const option of field.options) { + returnData.push({ + name: option.label, + value: option.id, + }); + } + } + } + } + if (operation === 'update') { + returnData.push({ + name: 'No Label', + value: 'null', + }); + } + return returnData; + }, + // Get all the labels to display them to user so that he can + // select them easily + async getDealLabels(this: ILoadOptionsFunctions): Promise { + const returnData: INodePropertyOptions[] = []; + const operation = this.getCurrentNodeParameter('operation') as string; + const { data } = await pipedriveApiRequest.call(this, 'GET', '/dealFields', {}); + for (const field of data) { + if (field.key === 'label') { + if (field.options) { + for (const option of field.options) { + returnData.push({ + name: option.label, + value: option.id, + }); + } + } + } + } + if (operation === 'update') { + returnData.push({ + name: 'No Label', + value: 'null', + }); + } + return returnData; + }, }, }; @@ -2455,8 +2691,10 @@ export class Pipedrive implements INodeType { const updateFields = this.getNodeParameter('updateFields', i) as IDataObject; addAdditionalFields(body, updateFields); + if (body.label === 'null') { + body.label = null; + } } - } else if (resource === 'file') { if (operation === 'create') { // ---------------------------------- @@ -2633,6 +2871,24 @@ export class Pipedrive implements INodeType { endpoint = `/organizations`; } + if (operation === 'update') { + // ---------------------------------- + // organization:update + // ---------------------------------- + + const id = this.getNodeParameter('organizationId', i) as string; + + requestMethod = 'PUT'; + endpoint = `/organizations/${id}`; + + const updateFields = this.getNodeParameter('updateFields', i) as IDataObject; + addAdditionalFields(body, updateFields); + + if (body.label === 'null') { + body.label = null; + } + + } } else if (resource === 'person') { if (operation === 'create') { // ---------------------------------- @@ -2736,6 +2992,10 @@ export class Pipedrive implements INodeType { const updateFields = this.getNodeParameter('updateFields', i) as IDataObject; addAdditionalFields(body, updateFields); + if (body.label === 'null') { + body.label = null; + } + } } else if (resource === 'product') { if (operation === 'getAll') {