mirror of
https://github.com/n8n-io/n8n.git
synced 2025-02-21 02:56:40 -08:00
⚡ Small improvements for Salesmate-Node
This commit is contained in:
parent
4987b29120
commit
01a2dd13d5
|
@ -19,9 +19,9 @@ export const activityOperations = [
|
|||
description: 'Create a activity',
|
||||
},
|
||||
{
|
||||
name: 'Update',
|
||||
value: 'update',
|
||||
description: 'Update a activity',
|
||||
name: 'Delete',
|
||||
value: 'delete',
|
||||
description: 'Delete a activity',
|
||||
},
|
||||
{
|
||||
name: 'Get',
|
||||
|
@ -34,9 +34,9 @@ export const activityOperations = [
|
|||
description: 'Get all companies',
|
||||
},
|
||||
{
|
||||
name: 'Delete',
|
||||
value: 'delete',
|
||||
description: 'Delete a activity',
|
||||
name: 'Update',
|
||||
value: 'update',
|
||||
description: 'Update a activity',
|
||||
},
|
||||
],
|
||||
default: 'create',
|
||||
|
@ -427,12 +427,14 @@ export const activityFields = [
|
|||
name: 'fields',
|
||||
type: 'string',
|
||||
default: '',
|
||||
description: 'Comma separated list of fields to return.',
|
||||
},
|
||||
{
|
||||
displayName: 'Sort By',
|
||||
name: 'sortBy',
|
||||
type: 'string',
|
||||
default: '',
|
||||
description: 'The field to sort by.',
|
||||
},
|
||||
{
|
||||
displayName: 'Sort Order',
|
||||
|
@ -440,11 +442,11 @@ export const activityFields = [
|
|||
type: 'options',
|
||||
options: [
|
||||
{
|
||||
name: 'Asc',
|
||||
name: 'ASC',
|
||||
value: 'asc',
|
||||
},
|
||||
{
|
||||
name: 'Desc',
|
||||
name: 'DESC',
|
||||
value: 'desc',
|
||||
},
|
||||
],
|
||||
|
@ -508,11 +510,11 @@ export const activityFields = [
|
|||
type: 'options',
|
||||
options: [
|
||||
{
|
||||
name: 'And',
|
||||
name: 'AND',
|
||||
value: 'AND',
|
||||
},
|
||||
{
|
||||
name: 'Or',
|
||||
name: 'OR',
|
||||
value: 'OR',
|
||||
},
|
||||
],
|
||||
|
|
|
@ -19,9 +19,9 @@ export const companyOperations = [
|
|||
description: 'Create a company',
|
||||
},
|
||||
{
|
||||
name: 'Update',
|
||||
value: 'update',
|
||||
description: 'Update a company',
|
||||
name: 'Delete',
|
||||
value: 'delete',
|
||||
description: 'Delete a company',
|
||||
},
|
||||
{
|
||||
name: 'Get',
|
||||
|
@ -34,9 +34,9 @@ export const companyOperations = [
|
|||
description: 'Get all companies',
|
||||
},
|
||||
{
|
||||
name: 'Delete',
|
||||
value: 'delete',
|
||||
description: 'Delete a company',
|
||||
name: 'Update',
|
||||
value: 'update',
|
||||
description: 'Update a company',
|
||||
},
|
||||
],
|
||||
default: 'create',
|
||||
|
@ -520,12 +520,14 @@ export const companyFields = [
|
|||
name: 'fields',
|
||||
type: 'string',
|
||||
default: '',
|
||||
description: 'Comma separated list of fields to return.',
|
||||
},
|
||||
{
|
||||
displayName: 'Sort By',
|
||||
name: 'sortBy',
|
||||
type: 'string',
|
||||
default: '',
|
||||
description: 'The field to sort by.',
|
||||
},
|
||||
{
|
||||
displayName: 'Sort Order',
|
||||
|
@ -533,11 +535,11 @@ export const companyFields = [
|
|||
type: 'options',
|
||||
options: [
|
||||
{
|
||||
name: 'Asc',
|
||||
name: 'ASC',
|
||||
value: 'asc',
|
||||
},
|
||||
{
|
||||
name: 'Desc',
|
||||
name: 'DESC',
|
||||
value: 'desc',
|
||||
},
|
||||
],
|
||||
|
@ -601,11 +603,11 @@ export const companyFields = [
|
|||
type: 'options',
|
||||
options: [
|
||||
{
|
||||
name: 'And',
|
||||
name: 'AND',
|
||||
value: 'AND',
|
||||
},
|
||||
{
|
||||
name: 'Or',
|
||||
name: 'OR',
|
||||
value: 'OR',
|
||||
},
|
||||
],
|
||||
|
|
|
@ -19,9 +19,9 @@ export const dealOperations = [
|
|||
description: 'Create a deal',
|
||||
},
|
||||
{
|
||||
name: 'Update',
|
||||
value: 'update',
|
||||
description: 'Update a deal',
|
||||
name: 'Delete',
|
||||
value: 'delete',
|
||||
description: 'Delete a deal',
|
||||
},
|
||||
{
|
||||
name: 'Get',
|
||||
|
@ -34,9 +34,9 @@ export const dealOperations = [
|
|||
description: 'Get all companies',
|
||||
},
|
||||
{
|
||||
name: 'Delete',
|
||||
value: 'delete',
|
||||
description: 'Delete a deal',
|
||||
name: 'Update',
|
||||
value: 'update',
|
||||
description: 'Update a deal',
|
||||
},
|
||||
],
|
||||
default: 'create',
|
||||
|
@ -691,12 +691,14 @@ export const dealFields = [
|
|||
name: 'fields',
|
||||
type: 'string',
|
||||
default: '',
|
||||
description: 'Comma separated list of fields to return.',
|
||||
},
|
||||
{
|
||||
displayName: 'Sort By',
|
||||
name: 'sortBy',
|
||||
type: 'string',
|
||||
default: '',
|
||||
description: 'The field to sort by.',
|
||||
},
|
||||
{
|
||||
displayName: 'Sort Order',
|
||||
|
@ -704,11 +706,11 @@ export const dealFields = [
|
|||
type: 'options',
|
||||
options: [
|
||||
{
|
||||
name: 'Asc',
|
||||
name: 'ASC',
|
||||
value: 'asc',
|
||||
},
|
||||
{
|
||||
name: 'Desc',
|
||||
name: 'DESC',
|
||||
value: 'desc',
|
||||
},
|
||||
],
|
||||
|
@ -772,11 +774,11 @@ export const dealFields = [
|
|||
type: 'options',
|
||||
options: [
|
||||
{
|
||||
name: 'And',
|
||||
name: 'AND',
|
||||
value: 'AND',
|
||||
},
|
||||
{
|
||||
name: 'Or',
|
||||
name: 'OR',
|
||||
value: 'OR',
|
||||
},
|
||||
],
|
||||
|
|
|
@ -65,3 +65,21 @@ export function validateJSON(json: string | undefined): any { // tslint:disable-
|
|||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Converts data from the Salesmate format into a simple object
|
||||
*
|
||||
* @export
|
||||
* @param {IDataObject[]} data
|
||||
* @returns {IDataObject}
|
||||
*/
|
||||
export function simplifySalesmateData(data: IDataObject[]): IDataObject {
|
||||
const returnData: IDataObject = {};
|
||||
|
||||
for (const item of data) {
|
||||
returnData[item.fieldName as string] = item.value;
|
||||
}
|
||||
|
||||
return returnData;
|
||||
}
|
||||
|
|
|
@ -12,6 +12,7 @@ import {
|
|||
import {
|
||||
salesmateApiRequest,
|
||||
salesmateApiRequestAllItems,
|
||||
simplifySalesmateData,
|
||||
validateJSON,
|
||||
} from './GenericFunctions';
|
||||
import {
|
||||
|
@ -289,12 +290,9 @@ export class Salesmate implements INodeType {
|
|||
const rawData = this.getNodeParameter('rawData', i) as boolean;
|
||||
responseData = await salesmateApiRequest.call(this, 'GET', `/v1/companies/${companyId}`);
|
||||
responseData = responseData.Data;
|
||||
|
||||
if (!rawData) {
|
||||
responseData = responseData.map((company: IDataObject) => {
|
||||
const aux: IDataObject = {};
|
||||
aux[company.fieldName as string] = company.value;
|
||||
return aux;
|
||||
});
|
||||
responseData = simplifySalesmateData(responseData);
|
||||
}
|
||||
}
|
||||
if (operation === 'getAll') {
|
||||
|
@ -314,9 +312,26 @@ export class Salesmate implements INodeType {
|
|||
qs.sortOrder = options.sortOrder as string;
|
||||
}
|
||||
if (options.fields) {
|
||||
if ((options.fields as string).trim() === '') {
|
||||
throw new Error('You have to add at least one field');
|
||||
}
|
||||
body.fields = (options.fields as string).split(',') as string[];
|
||||
} else {
|
||||
throw new Error('You have to add at least one field');
|
||||
body.fields = [
|
||||
'name',
|
||||
'description',
|
||||
'billingAddressLine1',
|
||||
'billingAddressLine2',
|
||||
'billingCity',
|
||||
'billingZipCode',
|
||||
'billingState',
|
||||
'billingCountry',
|
||||
'website',
|
||||
'owner',
|
||||
'tags',
|
||||
'photo',
|
||||
'createdAt',
|
||||
];
|
||||
}
|
||||
if (!jsonActive) {
|
||||
const filters: IDataObject[] = [];
|
||||
|
@ -332,7 +347,7 @@ export class Salesmate implements INodeType {
|
|||
};
|
||||
filter.condition = condition.condition;
|
||||
filter.data = condition.value;
|
||||
filters.push(filter)
|
||||
filters.push(filter);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -440,12 +455,9 @@ export class Salesmate implements INodeType {
|
|||
const rawData = this.getNodeParameter('rawData', i) as boolean;
|
||||
responseData = await salesmateApiRequest.call(this, 'GET', `/v1/activities/${activityId}`);
|
||||
responseData = responseData.Data;
|
||||
|
||||
if (!rawData) {
|
||||
responseData = responseData.map((activity: IDataObject) => {
|
||||
const aux: IDataObject = {};
|
||||
aux[activity.fieldName as string] = activity.value;
|
||||
return aux;
|
||||
});
|
||||
responseData = simplifySalesmateData(responseData);
|
||||
}
|
||||
}
|
||||
if (operation === 'getAll') {
|
||||
|
@ -465,9 +477,27 @@ export class Salesmate implements INodeType {
|
|||
qs.sortOrder = options.sortOrder as string;
|
||||
}
|
||||
if (options.fields) {
|
||||
if ((options.fields as string).trim() === '') {
|
||||
throw new Error('You have to add at least one field');
|
||||
}
|
||||
body.fields = (options.fields as string).split(',') as string[];
|
||||
} else {
|
||||
throw new Error('You have to add at least one field');
|
||||
body.fields = [
|
||||
'title',
|
||||
'dueDate',
|
||||
'description',
|
||||
'duration',
|
||||
'owner',
|
||||
'Deal.title',
|
||||
'PrimaryContact.name',
|
||||
'PrimaryContact.email',
|
||||
'PrimaryCompany.name',
|
||||
'PrimaryCompany.email',
|
||||
'tags',
|
||||
'type',
|
||||
'createdAt',
|
||||
'isCompleted',
|
||||
];
|
||||
}
|
||||
if (!jsonActive) {
|
||||
const filters: IDataObject[] = [];
|
||||
|
@ -483,7 +513,7 @@ export class Salesmate implements INodeType {
|
|||
};
|
||||
filter.condition = condition.condition;
|
||||
filter.data = condition.value;
|
||||
filters.push(filter)
|
||||
filters.push(filter);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -617,12 +647,9 @@ export class Salesmate implements INodeType {
|
|||
const rawData = this.getNodeParameter('rawData', i) as boolean;
|
||||
responseData = await salesmateApiRequest.call(this, 'GET', `/v1/deals/${dealId}`);
|
||||
responseData = responseData.Data;
|
||||
|
||||
if (!rawData) {
|
||||
responseData = responseData.map((deal: IDataObject) => {
|
||||
const aux: IDataObject = {};
|
||||
aux[deal.fieldName as string] = deal.value;
|
||||
return aux;
|
||||
});
|
||||
responseData = simplifySalesmateData(responseData);
|
||||
}
|
||||
}
|
||||
if (operation === 'getAll') {
|
||||
|
@ -641,10 +668,26 @@ export class Salesmate implements INodeType {
|
|||
if (options.sortOrder) {
|
||||
qs.sortOrder = options.sortOrder as string;
|
||||
}
|
||||
if (options.fields) {
|
||||
if (options.fields !== undefined) {
|
||||
if ((options.fields as string).trim() === '') {
|
||||
throw new Error('You have to add at least one field');
|
||||
}
|
||||
body.fields = (options.fields as string).split(',') as string[];
|
||||
} else {
|
||||
throw new Error('You have to add at least one field');
|
||||
body.fields = [
|
||||
'title',
|
||||
'PrimaryContact.name',
|
||||
'PrimaryContact.email',
|
||||
'PrimaryCompany.name',
|
||||
'PrimaryCompany.email',
|
||||
'dealValue',
|
||||
'priority',
|
||||
'stage',
|
||||
'status',
|
||||
'owner',
|
||||
'tags',
|
||||
'createdAt',
|
||||
];
|
||||
}
|
||||
if (!jsonActive) {
|
||||
const filters: IDataObject[] = [];
|
||||
|
@ -660,7 +703,7 @@ export class Salesmate implements INodeType {
|
|||
};
|
||||
filter.condition = condition.condition;
|
||||
filter.data = condition.value;
|
||||
filters.push(filter)
|
||||
filters.push(filter);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue