mirror of
https://github.com/n8n-io/n8n.git
synced 2024-11-10 06:34:05 -08:00
⚡ Improvements to Pipedrive node (#707)
This commit is contained in:
parent
4d5c166414
commit
13f71d3af0
|
@ -5,10 +5,12 @@ import {
|
|||
|
||||
import {
|
||||
IDataObject,
|
||||
ILoadOptionsFunctions,
|
||||
} from 'n8n-workflow';
|
||||
|
||||
import { OptionsWithUri } from 'request';
|
||||
|
||||
import {
|
||||
OptionsWithUri,
|
||||
} from 'request';
|
||||
|
||||
export interface ICustomInterface {
|
||||
name: string;
|
||||
|
@ -33,7 +35,7 @@ export interface ICustomProperties {
|
|||
* @param {object} body
|
||||
* @returns {Promise<any>}
|
||||
*/
|
||||
export async function pipedriveApiRequest(this: IHookFunctions | IExecuteFunctions, method: string, endpoint: string, body: IDataObject, query?: IDataObject, formData?: IDataObject, downloadFile?: boolean): Promise<any> { // tslint:disable-line:no-any
|
||||
export async function pipedriveApiRequest(this: IHookFunctions | IExecuteFunctions | ILoadOptionsFunctions, method: string, endpoint: string, body: IDataObject, query?: IDataObject, formData?: IDataObject, downloadFile?: boolean): Promise<any> { // tslint:disable-line:no-any
|
||||
const credentials = this.getCredentials('pipedriveApi');
|
||||
if (credentials === undefined) {
|
||||
throw new Error('No credentials got returned!');
|
||||
|
@ -66,6 +68,7 @@ export async function pipedriveApiRequest(this: IHookFunctions | IExecuteFunctio
|
|||
}
|
||||
|
||||
try {
|
||||
//@ts-ignore
|
||||
const responseData = await this.helpers.request(options);
|
||||
|
||||
if (downloadFile === true) {
|
||||
|
|
|
@ -1,12 +1,14 @@
|
|||
import {
|
||||
BINARY_ENCODING,
|
||||
IExecuteFunctions,
|
||||
ILoadOptionsFunctions,
|
||||
} from 'n8n-core';
|
||||
import {
|
||||
IDataObject,
|
||||
INodeTypeDescription,
|
||||
INodeExecutionData,
|
||||
INodeType,
|
||||
INodePropertyOptions,
|
||||
} from 'n8n-workflow';
|
||||
|
||||
import {
|
||||
|
@ -2047,7 +2049,66 @@ export class Pipedrive implements INodeType {
|
|||
description: 'How many results to return.',
|
||||
},
|
||||
|
||||
// ----------------------------------
|
||||
// person:getAll
|
||||
// ----------------------------------
|
||||
{
|
||||
displayName: 'Additional Fields',
|
||||
name: 'additionalFields',
|
||||
type: 'collection',
|
||||
placeholder: 'Add Field',
|
||||
displayOptions: {
|
||||
show: {
|
||||
operation: [
|
||||
'getAll',
|
||||
],
|
||||
resource: [
|
||||
'person',
|
||||
],
|
||||
},
|
||||
},
|
||||
default: {},
|
||||
options: [
|
||||
{
|
||||
displayName: 'Filter ID',
|
||||
name: 'filterId',
|
||||
type: 'options',
|
||||
typeOptions: {
|
||||
loadOptionsMethod: 'getFilters',
|
||||
},
|
||||
default: '',
|
||||
description: 'ID of the filter to use.',
|
||||
},
|
||||
{
|
||||
displayName: 'First Char',
|
||||
name: 'firstChar',
|
||||
type: 'string',
|
||||
default: '',
|
||||
description: 'If supplied, only persons whose name starts with the specified letter will be returned ',
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
methods = {
|
||||
loadOptions: {
|
||||
// Get all the filters to display them to user so that he can
|
||||
// select them easily
|
||||
async getFilters(this: ILoadOptionsFunctions): Promise<INodePropertyOptions[]> {
|
||||
const returnData: INodePropertyOptions[] = [];
|
||||
const { data } = await pipedriveApiRequest.call(this, 'GET', '/filters', {}, { type: 'people' });
|
||||
for (const filter of data) {
|
||||
const filterName = filter.name;
|
||||
const filterId = filter.id;
|
||||
returnData.push({
|
||||
name: filterName,
|
||||
value: filterId,
|
||||
});
|
||||
}
|
||||
return returnData;
|
||||
},
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
@ -2453,6 +2514,16 @@ export class Pipedrive implements INodeType {
|
|||
qs.limit = this.getNodeParameter('limit', i) as number;
|
||||
}
|
||||
|
||||
const additionalFields = this.getNodeParameter('additionalFields', i) as IDataObject;
|
||||
|
||||
if (additionalFields.filterId) {
|
||||
qs.filter_id = additionalFields.filterId as string;
|
||||
}
|
||||
|
||||
if (additionalFields.firstChar) {
|
||||
qs.first_char = additionalFields.firstChar as string;
|
||||
}
|
||||
|
||||
endpoint = `/persons`;
|
||||
|
||||
} else if (operation === 'update') {
|
||||
|
@ -2499,6 +2570,7 @@ export class Pipedrive implements INodeType {
|
|||
}
|
||||
|
||||
responseData = await pipedriveApiRequest.call(this, requestMethod, endpoint, body, qs, formData, downloadFile);
|
||||
|
||||
}
|
||||
|
||||
if (resource === 'file' && operation === 'download') {
|
||||
|
@ -2520,6 +2592,11 @@ export class Pipedrive implements INodeType {
|
|||
|
||||
items[i].binary![binaryPropertyName] = await this.helpers.prepareBinaryData(responseData.data);
|
||||
} else {
|
||||
|
||||
if (responseData.data === null) {
|
||||
responseData.data = [];
|
||||
}
|
||||
|
||||
if (Array.isArray(responseData.data)) {
|
||||
returnData.push.apply(returnData, responseData.data as IDataObject[]);
|
||||
} else {
|
||||
|
|
Loading…
Reference in a new issue