Small improvements for Salesmate-Node

This commit is contained in:
Jan Oberhauser
2020-01-22 00:17:29 -08:00
parent 4987b29120
commit 01a2dd13d5
5 changed files with 119 additions and 52 deletions

View File

@@ -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);
}
}
}