Small improvements to Affinity-Node

This commit is contained in:
Jan Oberhauser 2020-03-08 22:16:06 +01:00
parent 34d6d001d3
commit 4560d02823
4 changed files with 12 additions and 35 deletions

View file

@ -101,7 +101,7 @@ export class Affinity implements INodeType {
for (const person of persons) { for (const person of persons) {
let personName = `${person.first_name} ${person.last_name}`; let personName = `${person.first_name} ${person.last_name}`;
if (person.primary_email !== null) { if (person.primary_email !== null) {
personName+= ` (${person.primary_email})` personName+= ` (${person.primary_email})`;
} }
const personId = person.id; const personId = person.id;
returnData.push({ returnData.push({

View file

@ -98,10 +98,6 @@ export class AffinityTrigger implements INodeType {
name: 'list_entry.created', name: 'list_entry.created',
value: 'list_entry.created', value: 'list_entry.created',
}, },
{
name: 'list_entry.updated',
value: 'list_entry.updated',
},
{ {
name: 'list_entry.deleted', name: 'list_entry.deleted',
value: 'list_entry.deleted', value: 'list_entry.deleted',
@ -159,13 +155,6 @@ export class AffinityTrigger implements INodeType {
required: true, required: true,
description: 'Webhook events that will be enabled for that endpoint.', description: 'Webhook events that will be enabled for that endpoint.',
}, },
{
displayName: 'Resolve Data',
name: 'resolveData',
type: 'boolean',
default: true,
description: 'By default does the webhook-data only contain the ID of the object.<br />If this option gets activated it will resolve the data automatically.',
},
], ],
}; };
@ -239,25 +228,15 @@ export class AffinityTrigger implements INodeType {
async webhook(this: IWebhookFunctions): Promise<IWebhookResponseData> { async webhook(this: IWebhookFunctions): Promise<IWebhookResponseData> {
const bodyData = this.getBodyData(); const bodyData = this.getBodyData();
const resolveData = this.getNodeParameter('resolveData', false) as boolean;
if (bodyData.type === 'sample.webhook') { if (bodyData.type === 'sample.webhook') {
return {} return {};
}
if (resolveData === false) {
// Return the data as it got received
return {
workflowData: [
this.helpers.returnJsonArray(bodyData),
],
};
} }
let responseData: IDataObject = {}; let responseData: IDataObject = {};
if (bodyData.type && bodyData.body) { if (bodyData.type && bodyData.body) {
const resource = (bodyData.type as string).split('.')[0] const resource = (bodyData.type as string).split('.')[0];
//@ts-ignore //@ts-ignore
const id = bodyData.body.id; const id = bodyData.body.id;
responseData = await affinityApiRequest.call(this, 'GET', `/${mapResource(resource)}/${id}`); responseData = await affinityApiRequest.call(this, 'GET', `/${mapResource(resource)}/${id}`);

View file

@ -42,8 +42,8 @@ export async function affinityApiRequest(this: IExecuteFunctions | IWebhookFunct
return await this.helpers.request!(options); return await this.helpers.request!(options);
} catch (error) { } catch (error) {
if (error.response) { if (error.response) {
let errorMessage = error.response.body.message || error.response.body.description || error.message; const errorMessage = error.response.body.message || error.response.body.description || error.message;
throw new Error(`Affinity error response [${error.statusCode}]: ${errorMessage}`); throw new Error(`Affinity error response: ${errorMessage}`);
} }
throw error; throw error;
} }
@ -57,10 +57,8 @@ export async function affinityApiRequestAllItems(this: IHookFunctions | ILoadOpt
query.page_size = 500; query.page_size = 500;
let uri: string | undefined;
do { do {
responseData = await affinityApiRequest.call(this, method, resource, body, query, uri); responseData = await affinityApiRequest.call(this, method, resource, body, query);
// @ts-ignore // @ts-ignore
query.page_token = responseData.page_token; query.page_token = responseData.page_token;
returnData.push.apply(returnData, responseData[propertyName]); returnData.push.apply(returnData, responseData[propertyName]);
@ -75,7 +73,7 @@ export async function affinityApiRequestAllItems(this: IHookFunctions | ILoadOpt
export function eventsExist(subscriptions: string[], currentSubsriptions: string[]) { export function eventsExist(subscriptions: string[], currentSubsriptions: string[]) {
for (const subscription of currentSubsriptions) { for (const subscription of currentSubsriptions) {
if (!subscriptions.includes(subscription)) { if (!subscriptions.includes(subscription)) {
return false return false;
} }
} }
return true; return true;
@ -91,5 +89,5 @@ export function mapResource(key: string) {
list_entry: 'list-entries', list_entry: 'list-entries',
field: 'fields', field: 'fields',
file: 'files', file: 'files',
}[key] }[key];
} }

View file

@ -16,17 +16,17 @@ export const organizationOperations = [
{ {
name: 'Create', name: 'Create',
value: 'create', value: 'create',
description: 'Create a organization', description: 'Create an organization',
}, },
{ {
name: 'Delete', name: 'Delete',
value: 'delete', value: 'delete',
description: 'Delete a organization', description: 'Delete an organization',
}, },
{ {
name: 'Get', name: 'Get',
value: 'get', value: 'get',
description: 'Get a organization', description: 'Get an organization',
}, },
{ {
name: 'Get All', name: 'Get All',
@ -36,7 +36,7 @@ export const organizationOperations = [
{ {
name: 'Update', name: 'Update',
value: 'update', value: 'update',
description: 'Update a organization', description: 'Update an organization',
}, },
], ],
default: 'create', default: 'create',