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',
|
description: 'Create a activity',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: 'Update',
|
name: 'Delete',
|
||||||
value: 'update',
|
value: 'delete',
|
||||||
description: 'Update a activity',
|
description: 'Delete a activity',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: 'Get',
|
name: 'Get',
|
||||||
|
@ -34,9 +34,9 @@ export const activityOperations = [
|
||||||
description: 'Get all companies',
|
description: 'Get all companies',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: 'Delete',
|
name: 'Update',
|
||||||
value: 'delete',
|
value: 'update',
|
||||||
description: 'Delete a activity',
|
description: 'Update a activity',
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
default: 'create',
|
default: 'create',
|
||||||
|
@ -427,12 +427,14 @@ export const activityFields = [
|
||||||
name: 'fields',
|
name: 'fields',
|
||||||
type: 'string',
|
type: 'string',
|
||||||
default: '',
|
default: '',
|
||||||
|
description: 'Comma separated list of fields to return.',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
displayName: 'Sort By',
|
displayName: 'Sort By',
|
||||||
name: 'sortBy',
|
name: 'sortBy',
|
||||||
type: 'string',
|
type: 'string',
|
||||||
default: '',
|
default: '',
|
||||||
|
description: 'The field to sort by.',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
displayName: 'Sort Order',
|
displayName: 'Sort Order',
|
||||||
|
@ -440,11 +442,11 @@ export const activityFields = [
|
||||||
type: 'options',
|
type: 'options',
|
||||||
options: [
|
options: [
|
||||||
{
|
{
|
||||||
name: 'Asc',
|
name: 'ASC',
|
||||||
value: 'asc',
|
value: 'asc',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: 'Desc',
|
name: 'DESC',
|
||||||
value: 'desc',
|
value: 'desc',
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
|
@ -508,11 +510,11 @@ export const activityFields = [
|
||||||
type: 'options',
|
type: 'options',
|
||||||
options: [
|
options: [
|
||||||
{
|
{
|
||||||
name: 'And',
|
name: 'AND',
|
||||||
value: 'AND',
|
value: 'AND',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: 'Or',
|
name: 'OR',
|
||||||
value: 'OR',
|
value: 'OR',
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
|
|
|
@ -19,9 +19,9 @@ export const companyOperations = [
|
||||||
description: 'Create a company',
|
description: 'Create a company',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: 'Update',
|
name: 'Delete',
|
||||||
value: 'update',
|
value: 'delete',
|
||||||
description: 'Update a company',
|
description: 'Delete a company',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: 'Get',
|
name: 'Get',
|
||||||
|
@ -34,9 +34,9 @@ export const companyOperations = [
|
||||||
description: 'Get all companies',
|
description: 'Get all companies',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: 'Delete',
|
name: 'Update',
|
||||||
value: 'delete',
|
value: 'update',
|
||||||
description: 'Delete a company',
|
description: 'Update a company',
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
default: 'create',
|
default: 'create',
|
||||||
|
@ -520,12 +520,14 @@ export const companyFields = [
|
||||||
name: 'fields',
|
name: 'fields',
|
||||||
type: 'string',
|
type: 'string',
|
||||||
default: '',
|
default: '',
|
||||||
|
description: 'Comma separated list of fields to return.',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
displayName: 'Sort By',
|
displayName: 'Sort By',
|
||||||
name: 'sortBy',
|
name: 'sortBy',
|
||||||
type: 'string',
|
type: 'string',
|
||||||
default: '',
|
default: '',
|
||||||
|
description: 'The field to sort by.',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
displayName: 'Sort Order',
|
displayName: 'Sort Order',
|
||||||
|
@ -533,11 +535,11 @@ export const companyFields = [
|
||||||
type: 'options',
|
type: 'options',
|
||||||
options: [
|
options: [
|
||||||
{
|
{
|
||||||
name: 'Asc',
|
name: 'ASC',
|
||||||
value: 'asc',
|
value: 'asc',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: 'Desc',
|
name: 'DESC',
|
||||||
value: 'desc',
|
value: 'desc',
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
|
@ -601,11 +603,11 @@ export const companyFields = [
|
||||||
type: 'options',
|
type: 'options',
|
||||||
options: [
|
options: [
|
||||||
{
|
{
|
||||||
name: 'And',
|
name: 'AND',
|
||||||
value: 'AND',
|
value: 'AND',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: 'Or',
|
name: 'OR',
|
||||||
value: 'OR',
|
value: 'OR',
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
|
|
|
@ -19,9 +19,9 @@ export const dealOperations = [
|
||||||
description: 'Create a deal',
|
description: 'Create a deal',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: 'Update',
|
name: 'Delete',
|
||||||
value: 'update',
|
value: 'delete',
|
||||||
description: 'Update a deal',
|
description: 'Delete a deal',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: 'Get',
|
name: 'Get',
|
||||||
|
@ -34,9 +34,9 @@ export const dealOperations = [
|
||||||
description: 'Get all companies',
|
description: 'Get all companies',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: 'Delete',
|
name: 'Update',
|
||||||
value: 'delete',
|
value: 'update',
|
||||||
description: 'Delete a deal',
|
description: 'Update a deal',
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
default: 'create',
|
default: 'create',
|
||||||
|
@ -691,12 +691,14 @@ export const dealFields = [
|
||||||
name: 'fields',
|
name: 'fields',
|
||||||
type: 'string',
|
type: 'string',
|
||||||
default: '',
|
default: '',
|
||||||
|
description: 'Comma separated list of fields to return.',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
displayName: 'Sort By',
|
displayName: 'Sort By',
|
||||||
name: 'sortBy',
|
name: 'sortBy',
|
||||||
type: 'string',
|
type: 'string',
|
||||||
default: '',
|
default: '',
|
||||||
|
description: 'The field to sort by.',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
displayName: 'Sort Order',
|
displayName: 'Sort Order',
|
||||||
|
@ -704,11 +706,11 @@ export const dealFields = [
|
||||||
type: 'options',
|
type: 'options',
|
||||||
options: [
|
options: [
|
||||||
{
|
{
|
||||||
name: 'Asc',
|
name: 'ASC',
|
||||||
value: 'asc',
|
value: 'asc',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: 'Desc',
|
name: 'DESC',
|
||||||
value: 'desc',
|
value: 'desc',
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
|
@ -772,11 +774,11 @@ export const dealFields = [
|
||||||
type: 'options',
|
type: 'options',
|
||||||
options: [
|
options: [
|
||||||
{
|
{
|
||||||
name: 'And',
|
name: 'AND',
|
||||||
value: 'AND',
|
value: 'AND',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: 'Or',
|
name: 'OR',
|
||||||
value: 'OR',
|
value: 'OR',
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
|
|
|
@ -65,3 +65,21 @@ export function validateJSON(json: string | undefined): any { // tslint:disable-
|
||||||
}
|
}
|
||||||
return result;
|
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 {
|
import {
|
||||||
salesmateApiRequest,
|
salesmateApiRequest,
|
||||||
salesmateApiRequestAllItems,
|
salesmateApiRequestAllItems,
|
||||||
|
simplifySalesmateData,
|
||||||
validateJSON,
|
validateJSON,
|
||||||
} from './GenericFunctions';
|
} from './GenericFunctions';
|
||||||
import {
|
import {
|
||||||
|
@ -289,12 +290,9 @@ export class Salesmate implements INodeType {
|
||||||
const rawData = this.getNodeParameter('rawData', i) as boolean;
|
const rawData = this.getNodeParameter('rawData', i) as boolean;
|
||||||
responseData = await salesmateApiRequest.call(this, 'GET', `/v1/companies/${companyId}`);
|
responseData = await salesmateApiRequest.call(this, 'GET', `/v1/companies/${companyId}`);
|
||||||
responseData = responseData.Data;
|
responseData = responseData.Data;
|
||||||
|
|
||||||
if (!rawData) {
|
if (!rawData) {
|
||||||
responseData = responseData.map((company: IDataObject) => {
|
responseData = simplifySalesmateData(responseData);
|
||||||
const aux: IDataObject = {};
|
|
||||||
aux[company.fieldName as string] = company.value;
|
|
||||||
return aux;
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (operation === 'getAll') {
|
if (operation === 'getAll') {
|
||||||
|
@ -314,9 +312,26 @@ export class Salesmate implements INodeType {
|
||||||
qs.sortOrder = options.sortOrder as string;
|
qs.sortOrder = options.sortOrder as string;
|
||||||
}
|
}
|
||||||
if (options.fields) {
|
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[];
|
body.fields = (options.fields as string).split(',') as string[];
|
||||||
} else {
|
} 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) {
|
if (!jsonActive) {
|
||||||
const filters: IDataObject[] = [];
|
const filters: IDataObject[] = [];
|
||||||
|
@ -332,7 +347,7 @@ export class Salesmate implements INodeType {
|
||||||
};
|
};
|
||||||
filter.condition = condition.condition;
|
filter.condition = condition.condition;
|
||||||
filter.data = condition.value;
|
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;
|
const rawData = this.getNodeParameter('rawData', i) as boolean;
|
||||||
responseData = await salesmateApiRequest.call(this, 'GET', `/v1/activities/${activityId}`);
|
responseData = await salesmateApiRequest.call(this, 'GET', `/v1/activities/${activityId}`);
|
||||||
responseData = responseData.Data;
|
responseData = responseData.Data;
|
||||||
|
|
||||||
if (!rawData) {
|
if (!rawData) {
|
||||||
responseData = responseData.map((activity: IDataObject) => {
|
responseData = simplifySalesmateData(responseData);
|
||||||
const aux: IDataObject = {};
|
|
||||||
aux[activity.fieldName as string] = activity.value;
|
|
||||||
return aux;
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (operation === 'getAll') {
|
if (operation === 'getAll') {
|
||||||
|
@ -465,9 +477,27 @@ export class Salesmate implements INodeType {
|
||||||
qs.sortOrder = options.sortOrder as string;
|
qs.sortOrder = options.sortOrder as string;
|
||||||
}
|
}
|
||||||
if (options.fields) {
|
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[];
|
body.fields = (options.fields as string).split(',') as string[];
|
||||||
} else {
|
} 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) {
|
if (!jsonActive) {
|
||||||
const filters: IDataObject[] = [];
|
const filters: IDataObject[] = [];
|
||||||
|
@ -483,7 +513,7 @@ export class Salesmate implements INodeType {
|
||||||
};
|
};
|
||||||
filter.condition = condition.condition;
|
filter.condition = condition.condition;
|
||||||
filter.data = condition.value;
|
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;
|
const rawData = this.getNodeParameter('rawData', i) as boolean;
|
||||||
responseData = await salesmateApiRequest.call(this, 'GET', `/v1/deals/${dealId}`);
|
responseData = await salesmateApiRequest.call(this, 'GET', `/v1/deals/${dealId}`);
|
||||||
responseData = responseData.Data;
|
responseData = responseData.Data;
|
||||||
|
|
||||||
if (!rawData) {
|
if (!rawData) {
|
||||||
responseData = responseData.map((deal: IDataObject) => {
|
responseData = simplifySalesmateData(responseData);
|
||||||
const aux: IDataObject = {};
|
|
||||||
aux[deal.fieldName as string] = deal.value;
|
|
||||||
return aux;
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (operation === 'getAll') {
|
if (operation === 'getAll') {
|
||||||
|
@ -641,10 +668,26 @@ export class Salesmate implements INodeType {
|
||||||
if (options.sortOrder) {
|
if (options.sortOrder) {
|
||||||
qs.sortOrder = options.sortOrder as string;
|
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[];
|
body.fields = (options.fields as string).split(',') as string[];
|
||||||
} else {
|
} 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) {
|
if (!jsonActive) {
|
||||||
const filters: IDataObject[] = [];
|
const filters: IDataObject[] = [];
|
||||||
|
@ -660,7 +703,7 @@ export class Salesmate implements INodeType {
|
||||||
};
|
};
|
||||||
filter.condition = condition.condition;
|
filter.condition = condition.condition;
|
||||||
filter.data = condition.value;
|
filter.data = condition.value;
|
||||||
filters.push(filter)
|
filters.push(filter);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue