🔀 Merge branch 'rodrigoscdc-pipe-dealactivity'

This commit is contained in:
Jan Oberhauser 2021-10-09 14:33:15 -05:00
commit 8618415772
2 changed files with 143 additions and 98 deletions

View file

@ -6,6 +6,7 @@ import {
import { import {
IDataObject, IDataObject,
ILoadOptionsFunctions, ILoadOptionsFunctions,
INodePropertyOptions,
NodeApiError, NodeApiError,
NodeOperationError, NodeOperationError,
} from 'n8n-workflow'; } from 'n8n-workflow';
@ -261,3 +262,16 @@ export function pipedriveResolveCustomProperties(customProperties: ICustomProper
} }
} }
export function sortOptionParameters(optionParameters: INodePropertyOptions[]): INodePropertyOptions[] {
optionParameters.sort((a, b) => {
const aName = a.name.toLowerCase();
const bName = b.name.toLowerCase();
if (aName < bName) { return -1; }
if (aName > bName) { return 1; }
return 0;
});
return optionParameters;
}

View file

@ -19,6 +19,7 @@ import {
pipedriveEncodeCustomProperties, pipedriveEncodeCustomProperties,
pipedriveGetCustomProperties, pipedriveGetCustomProperties,
pipedriveResolveCustomProperties, pipedriveResolveCustomProperties,
sortOptionParameters,
} from './GenericFunctions'; } from './GenericFunctions';
import { import {
@ -118,6 +119,10 @@ export class Pipedrive implements INodeType {
name: 'Deal', name: 'Deal',
value: 'deal', value: 'deal',
}, },
{
name: 'Deal Activity',
value: 'dealActivity',
},
{ {
name: 'Deal Product', name: 'Deal Product',
value: 'dealProduct', value: 'dealProduct',
@ -250,6 +255,27 @@ export class Pipedrive implements INodeType {
description: 'The operation to perform.', description: 'The operation to perform.',
}, },
{
displayName: 'Operation',
name: 'operation',
type: 'options',
displayOptions: {
show: {
resource: [
'dealActivity',
],
},
},
options: [
{
name: 'Get All',
value: 'getAll',
description: 'Get all activities of a deal',
},
],
default: 'getAll',
},
{ {
displayName: 'Operation', displayName: 'Operation',
name: 'operation', name: 'operation',
@ -3423,6 +3449,64 @@ export class Pipedrive implements INodeType {
description: 'How many results to return.', description: 'How many results to return.',
}, },
// ----------------------------------
// dealActivities:getAll
// ----------------------------------
{
displayName: 'Deal ID',
name: 'dealId',
type: 'options',
default: '',
typeOptions: {
loadOptionsMethod: 'getDeals',
},
required: true,
displayOptions: {
show: {
operation: [
'getAll',
],
resource: [
'dealActivity',
],
},
},
description: 'The ID of the deal whose activity to retrieve',
},
{
displayName: 'Additional Fields',
name: 'additionalFields',
type: 'collection',
placeholder: 'Add Field',
displayOptions: {
show: {
operation: [
'getAll',
],
resource: [
'dealActivity',
],
},
},
default: {},
options: [
{
displayName: 'Done',
name: 'done',
type: 'boolean',
default: false,
description: 'Whether the activity is done or not.',
},
{
displayName: 'Exclude Activity IDs',
name: 'exclude',
type: 'string',
default: '',
description: 'A comma separated Activity Ids, to exclude from result. Ex. 4, 9, 11, ...',
},
],
},
// ---------------------------------------- // ----------------------------------------
// lead: getAll // lead: getAll
// ---------------------------------------- // ----------------------------------------
@ -3807,15 +3891,7 @@ export class Pipedrive implements INodeType {
}); });
} }
returnData.sort((a, b) => { return sortOptionParameters(returnData);
const aName = a.name.toLowerCase();
const bName = b.name.toLowerCase();
if (aName < bName) { return -1; }
if (aName > bName) { return 1; }
return 0;
});
return returnData;
}, },
// Get all Filters to display them to user so that he can // Get all Filters to display them to user so that he can
// select them easily // select them easily
@ -3836,15 +3912,7 @@ export class Pipedrive implements INodeType {
}); });
} }
returnData.sort((a, b) => { return sortOptionParameters(returnData);
const aName = a.name.toLowerCase();
const bName = b.name.toLowerCase();
if (aName < bName) { return -1; }
if (aName > bName) { return 1; }
return 0;
});
return returnData;
}, },
// Get all Organizations to display them to user so that he can // Get all Organizations to display them to user so that he can
// select them easily // select them easily
@ -3858,15 +3926,7 @@ export class Pipedrive implements INodeType {
}); });
} }
returnData.sort((a, b) => { return sortOptionParameters(returnData);
const aName = a.name.toLowerCase();
const bName = b.name.toLowerCase();
if (aName < bName) { return -1; }
if (aName > bName) { return 1; }
return 0;
});
return returnData;
}, },
// Get all Organizations to display them to user so that he can // Get all Organizations to display them to user so that he can
// select them easily // select them easily
@ -3882,15 +3942,7 @@ export class Pipedrive implements INodeType {
} }
} }
returnData.sort((a, b) => { return sortOptionParameters(returnData);
const aName = a.name.toLowerCase();
const bName = b.name.toLowerCase();
if (aName < bName) { return -1; }
if (aName > bName) { return 1; }
return 0;
});
return returnData;
}, },
// Get all Deals to display them to user so that he can // Get all Deals to display them to user so that he can
// select them easily // select them easily
@ -3898,7 +3950,7 @@ export class Pipedrive implements INodeType {
const { data } = await pipedriveApiRequest.call(this, 'GET', '/deals', {}) as { const { data } = await pipedriveApiRequest.call(this, 'GET', '/deals', {}) as {
data: Array<{ id: string; title: string; }> data: Array<{ id: string; title: string; }>
}; };
return data.map(({ id, title }) => ({ value: id, name: title })); return sortOptionParameters(data.map(({ id, title }) => ({ value: id, name: title })));
}, },
// Get all Products to display them to user so that he can // Get all Products to display them to user so that he can
// select them easily // select them easily
@ -3906,7 +3958,7 @@ export class Pipedrive implements INodeType {
const { data } = await pipedriveApiRequest.call(this, 'GET', '/products', {}) as { const { data } = await pipedriveApiRequest.call(this, 'GET', '/products', {}) as {
data: Array<{ id: string; name: string; }> data: Array<{ id: string; name: string; }>
}; };
return data.map(({ id, name }) => ({ value: id, name })); return sortOptionParameters(data.map(({ id, name }) => ({ value: id, name })));
}, },
// Get all Products related to a deal and display them to user so that he can // Get all Products related to a deal and display them to user so that he can
// select them easily // select them easily
@ -3916,7 +3968,7 @@ export class Pipedrive implements INodeType {
const { data } = await pipedriveApiRequest.call(this, 'GET', `/deals/${dealId}/products`, {}) as { const { data } = await pipedriveApiRequest.call(this, 'GET', `/deals/${dealId}/products`, {}) as {
data: Array<{ id: string; name: string; }> data: Array<{ id: string; name: string; }>
}; };
return data.map(({ id, name }) => ({ value: id, name })); return sortOptionParameters(data.map(({ id, name }) => ({ value: id, name })));
}, },
// Get all Stages to display them to user so that he can // Get all Stages to display them to user so that he can
// select them easily // select them easily
@ -3930,15 +3982,7 @@ export class Pipedrive implements INodeType {
}); });
} }
returnData.sort((a, b) => { return sortOptionParameters(returnData);
const aName = a.name.toLowerCase();
const bName = b.name.toLowerCase();
if (aName < bName) { return -1; }
if (aName > bName) { return 1; }
return 0;
});
return returnData;
}, },
// Get all the Organization Custom Fields to display them to user so that he can // Get all the Organization Custom Fields to display them to user so that he can
// select them easily // select them easily
@ -3954,15 +3998,7 @@ export class Pipedrive implements INodeType {
} }
} }
returnData.sort((a, b) => { return sortOptionParameters(returnData);
const aName = a.name.toLowerCase();
const bName = b.name.toLowerCase();
if (aName < bName) { return -1; }
if (aName > bName) { return 1; }
return 0;
});
return returnData;
}, },
// Get all the Deal Custom Fields to display them to user so that he can // Get all the Deal Custom Fields to display them to user so that he can
// select them easily // select them easily
@ -3978,15 +4014,7 @@ export class Pipedrive implements INodeType {
} }
} }
returnData.sort((a, b) => { return sortOptionParameters(returnData);
const aName = a.name.toLowerCase();
const bName = b.name.toLowerCase();
if (aName < bName) { return -1; }
if (aName > bName) { return 1; }
return 0;
});
return returnData;
}, },
// Get all the Person Custom Fields to display them to user so that he can // Get all the Person Custom Fields to display them to user so that he can
// select them easily // select them easily
@ -4002,15 +4030,7 @@ export class Pipedrive implements INodeType {
} }
} }
returnData.sort((a, b) => { return sortOptionParameters(returnData);
const aName = a.name.toLowerCase();
const bName = b.name.toLowerCase();
if (aName < bName) { return -1; }
if (aName > bName) { return 1; }
return 0;
});
return returnData;
}, },
// Get all the person labels to display them to user so that he can // Get all the person labels to display them to user so that he can
// select them easily // select them easily
@ -4031,13 +4051,7 @@ export class Pipedrive implements INodeType {
} }
} }
returnData.sort((a, b) => { sortOptionParameters(returnData);
const aName = a.name.toLowerCase();
const bName = b.name.toLowerCase();
if (aName < bName) { return -1; }
if (aName > bName) { return 1; }
return 0;
});
if (operation === 'update') { if (operation === 'update') {
returnData.push({ returnData.push({
@ -4066,13 +4080,7 @@ export class Pipedrive implements INodeType {
} }
} }
returnData.sort((a, b) => { sortOptionParameters(returnData);
const aName = a.name.toLowerCase();
const bName = b.name.toLowerCase();
if (aName < bName) { return -1; }
if (aName > bName) { return 1; }
return 0;
});
if (operation === 'update') { if (operation === 'update') {
returnData.push({ returnData.push({
@ -4090,7 +4098,7 @@ export class Pipedrive implements INodeType {
data: Array<{ id: string; name: string; }> data: Array<{ id: string; name: string; }>
}; };
return data.map(({ id, name }) => ({ value: id, name })); return sortOptionParameters(data.map(({ id, name }) => ({ value: id, name })));
}, },
// Get all the lead labels to display them to user so that he can // Get all the lead labels to display them to user so that he can
@ -4100,7 +4108,7 @@ export class Pipedrive implements INodeType {
data: Array<{ id: string; name: string; }> data: Array<{ id: string; name: string; }>
}; };
return data.map(({ id, name }) => ({ value: id, name })); return sortOptionParameters(data.map(({ id, name }) => ({ value: id, name })));
}, },
// Get all the labels to display them to user so that he can // Get all the labels to display them to user so that he can
@ -4122,13 +4130,7 @@ export class Pipedrive implements INodeType {
} }
} }
returnData.sort((a, b) => { sortOptionParameters(returnData);
const aName = a.name.toLowerCase();
const bName = b.name.toLowerCase();
if (aName < bName) { return -1; }
if (aName > bName) { return 1; }
return 0;
});
if (operation === 'update') { if (operation === 'update') {
returnData.push({ returnData.push({
@ -4387,6 +4389,35 @@ export class Pipedrive implements INodeType {
} }
} else if (resource === 'dealActivity') {
if (operation === 'getAll') {
// ----------------------------------
// dealActivity: getAll
// ----------------------------------
requestMethod = 'GET';
const dealId = this.getNodeParameter('dealId', i) as string;
returnAll = this.getNodeParameter('returnAll', i) as boolean;
if (returnAll === false) {
qs.limit = this.getNodeParameter('limit', i) as number;
}
const additionalFields = this.getNodeParameter('additionalFields', i) as IDataObject;
if (additionalFields.exclude) {
qs.exclude = (additionalFields.exclude as string);
}
if (additionalFields && additionalFields.done !== undefined) {
qs.done = additionalFields.done === true ? 1 : 0;
}
endpoint = `/deals/${dealId}/activities`;
}
} else if (resource === 'dealProduct') { } else if (resource === 'dealProduct') {
if (operation === 'add') { if (operation === 'add') {