mirror of
https://github.com/n8n-io/n8n.git
synced 2025-01-12 05:17:28 -08:00
⚡ Small improvements to Affinity-Node
This commit is contained in:
parent
34d6d001d3
commit
4560d02823
|
@ -101,7 +101,7 @@ export class Affinity implements INodeType {
|
|||
for (const person of persons) {
|
||||
let personName = `${person.first_name} ${person.last_name}`;
|
||||
if (person.primary_email !== null) {
|
||||
personName+= ` (${person.primary_email})`
|
||||
personName+= ` (${person.primary_email})`;
|
||||
}
|
||||
const personId = person.id;
|
||||
returnData.push({
|
||||
|
|
|
@ -98,10 +98,6 @@ export class AffinityTrigger implements INodeType {
|
|||
name: 'list_entry.created',
|
||||
value: 'list_entry.created',
|
||||
},
|
||||
{
|
||||
name: 'list_entry.updated',
|
||||
value: 'list_entry.updated',
|
||||
},
|
||||
{
|
||||
name: 'list_entry.deleted',
|
||||
value: 'list_entry.deleted',
|
||||
|
@ -159,13 +155,6 @@ export class AffinityTrigger implements INodeType {
|
|||
required: true,
|
||||
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> {
|
||||
const bodyData = this.getBodyData();
|
||||
const resolveData = this.getNodeParameter('resolveData', false) as boolean;
|
||||
|
||||
if (bodyData.type === 'sample.webhook') {
|
||||
return {}
|
||||
}
|
||||
|
||||
if (resolveData === false) {
|
||||
// Return the data as it got received
|
||||
return {
|
||||
workflowData: [
|
||||
this.helpers.returnJsonArray(bodyData),
|
||||
],
|
||||
};
|
||||
return {};
|
||||
}
|
||||
|
||||
let responseData: IDataObject = {};
|
||||
|
||||
if (bodyData.type && bodyData.body) {
|
||||
const resource = (bodyData.type as string).split('.')[0]
|
||||
const resource = (bodyData.type as string).split('.')[0];
|
||||
//@ts-ignore
|
||||
const id = bodyData.body.id;
|
||||
responseData = await affinityApiRequest.call(this, 'GET', `/${mapResource(resource)}/${id}`);
|
||||
|
|
|
@ -42,8 +42,8 @@ export async function affinityApiRequest(this: IExecuteFunctions | IWebhookFunct
|
|||
return await this.helpers.request!(options);
|
||||
} catch (error) {
|
||||
if (error.response) {
|
||||
let errorMessage = error.response.body.message || error.response.body.description || error.message;
|
||||
throw new Error(`Affinity error response [${error.statusCode}]: ${errorMessage}`);
|
||||
const errorMessage = error.response.body.message || error.response.body.description || error.message;
|
||||
throw new Error(`Affinity error response: ${errorMessage}`);
|
||||
}
|
||||
throw error;
|
||||
}
|
||||
|
@ -57,10 +57,8 @@ export async function affinityApiRequestAllItems(this: IHookFunctions | ILoadOpt
|
|||
|
||||
query.page_size = 500;
|
||||
|
||||
let uri: string | undefined;
|
||||
|
||||
do {
|
||||
responseData = await affinityApiRequest.call(this, method, resource, body, query, uri);
|
||||
responseData = await affinityApiRequest.call(this, method, resource, body, query);
|
||||
// @ts-ignore
|
||||
query.page_token = responseData.page_token;
|
||||
returnData.push.apply(returnData, responseData[propertyName]);
|
||||
|
@ -75,7 +73,7 @@ export async function affinityApiRequestAllItems(this: IHookFunctions | ILoadOpt
|
|||
export function eventsExist(subscriptions: string[], currentSubsriptions: string[]) {
|
||||
for (const subscription of currentSubsriptions) {
|
||||
if (!subscriptions.includes(subscription)) {
|
||||
return false
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
|
@ -91,5 +89,5 @@ export function mapResource(key: string) {
|
|||
list_entry: 'list-entries',
|
||||
field: 'fields',
|
||||
file: 'files',
|
||||
}[key]
|
||||
}[key];
|
||||
}
|
||||
|
|
|
@ -16,17 +16,17 @@ export const organizationOperations = [
|
|||
{
|
||||
name: 'Create',
|
||||
value: 'create',
|
||||
description: 'Create a organization',
|
||||
description: 'Create an organization',
|
||||
},
|
||||
{
|
||||
name: 'Delete',
|
||||
value: 'delete',
|
||||
description: 'Delete a organization',
|
||||
description: 'Delete an organization',
|
||||
},
|
||||
{
|
||||
name: 'Get',
|
||||
value: 'get',
|
||||
description: 'Get a organization',
|
||||
description: 'Get an organization',
|
||||
},
|
||||
{
|
||||
name: 'Get All',
|
||||
|
@ -36,7 +36,7 @@ export const organizationOperations = [
|
|||
{
|
||||
name: 'Update',
|
||||
value: 'update',
|
||||
description: 'Update a organization',
|
||||
description: 'Update an organization',
|
||||
},
|
||||
],
|
||||
default: 'create',
|
||||
|
|
Loading…
Reference in a new issue