Make event on Eventbrite Trigger Node optional (#2829)

* Set `event` property as optional

* Add some parameter descriptions

To please nodelinter, mostly.

* Fix UI complaining about missing parameter.

* 🚨 Fixed lint isssues

*  Improvements

Co-authored-by: Jonathan Bennetts <jonathan.bennetts@gmail.com>
Co-authored-by: ricardo <ricardoespinoza105@gmail.com>
This commit is contained in:
Francesco Pongiluppi 2022-04-14 09:36:46 +02:00 committed by GitHub
parent 29fdd77d7b
commit 5e54249c41
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 11 deletions

View file

@ -26,6 +26,7 @@ export class EventbriteTrigger implements INodeType {
group: ['trigger'], group: ['trigger'],
version: 1, version: 1,
description: 'Handle Eventbrite events via webhooks', description: 'Handle Eventbrite events via webhooks',
subtitle: '={{$parameter["event"]}}',
defaults: { defaults: {
name: 'Eventbrite Trigger', name: 'Eventbrite Trigger',
}, },
@ -79,7 +80,6 @@ export class EventbriteTrigger implements INodeType {
}, },
], ],
default: 'privateKey', default: 'privateKey',
description: 'The resource to operate on.',
}, },
{ {
displayName: 'Organization', displayName: 'Organization',
@ -90,7 +90,7 @@ export class EventbriteTrigger implements INodeType {
loadOptionsMethod: 'getOrganizations', loadOptionsMethod: 'getOrganizations',
}, },
default: '', default: '',
description: '', description: 'The Eventbrite Organization to work on',
}, },
{ {
displayName: 'Event', displayName: 'Event',
@ -104,7 +104,7 @@ export class EventbriteTrigger implements INodeType {
loadOptionsMethod: 'getEvents', loadOptionsMethod: 'getEvents',
}, },
default: '', default: '',
description: '', description: 'Limit the triggers to this event',
}, },
{ {
displayName: 'Actions', displayName: 'Actions',
@ -174,14 +174,14 @@ export class EventbriteTrigger implements INodeType {
], ],
required: true, required: true,
default: [], default: [],
description: '', description: 'One or more action to subscribe to.',
}, },
{ {
displayName: 'Resolve Data', displayName: 'Resolve Data',
name: 'resolveData', name: 'resolveData',
type: 'boolean', type: 'boolean',
default: true, default: true,
description: 'By default does the webhook-data only contain the URL to receive the object data manually. If this option gets activated, it will resolve the data automatically.', description: 'By default does the webhook-data only contain the URL to receive the object data manually. If this option gets activated, it will resolve the data automatically',
}, },
], ],
}; };
@ -206,7 +206,7 @@ export class EventbriteTrigger implements INodeType {
// Get all the available events to display them to user so that he can // Get all the available events to display them to user so that he can
// select them easily // select them easily
async getEvents(this: ILoadOptionsFunctions): Promise<INodePropertyOptions[]> { async getEvents(this: ILoadOptionsFunctions): Promise<INodePropertyOptions[]> {
const returnData: INodePropertyOptions[] = []; const returnData: INodePropertyOptions[] = [{ name: 'All', value: 'all' }];
const organization = this.getCurrentNodeParameter('organization'); const organization = this.getCurrentNodeParameter('organization');
const events = await eventbriteApiRequestAllItems.call(this, 'events', 'GET', `/organizations/${organization}/events`); const events = await eventbriteApiRequestAllItems.call(this, 'events', 'GET', `/organizations/${organization}/events`);
for (const event of events) { for (const event of events) {
@ -264,9 +264,10 @@ export class EventbriteTrigger implements INodeType {
actions: actions.join(','), actions: actions.join(','),
event_id: event, event_id: event,
}; };
if (event === 'all' || event === '') {
delete body.event_id;
}
const responseData = await eventbriteApiRequest.call(this, 'POST', endpoint, body); const responseData = await eventbriteApiRequest.call(this, 'POST', endpoint, body);
webhookData.webhookId = responseData.id; webhookData.webhookId = responseData.id;
return true; return true;
}, },

View file

@ -11,7 +11,7 @@ import {
} from 'n8n-core'; } from 'n8n-core';
import { import {
IDataObject, NodeApiError, NodeOperationError, IDataObject, JsonObject, NodeApiError, NodeOperationError,
} from 'n8n-workflow'; } from 'n8n-workflow';
export async function eventbriteApiRequest(this: IHookFunctions | IExecuteFunctions | IExecuteSingleFunctions | ILoadOptionsFunctions | IWebhookFunctions, method: string, resource: string, body: any = {}, qs: IDataObject = {}, uri?: string, option: IDataObject = {}): Promise<any> { // tslint:disable-line:no-any export async function eventbriteApiRequest(this: IHookFunctions | IExecuteFunctions | IExecuteSingleFunctions | ILoadOptionsFunctions | IWebhookFunctions, method: string, resource: string, body: any = {}, qs: IDataObject = {}, uri?: string, option: IDataObject = {}): Promise<any> { // tslint:disable-line:no-any
@ -38,13 +38,12 @@ export async function eventbriteApiRequest(this: IHookFunctions | IExecuteFuncti
} }
options.headers!['Authorization'] = `Bearer ${credentials.apiKey}`; options.headers!['Authorization'] = `Bearer ${credentials.apiKey}`;
return await this.helpers.request!(options); return await this.helpers.request!(options);
} else { } else {
return await this.helpers.requestOAuth2!.call(this, 'eventbriteOAuth2Api', options); return await this.helpers.requestOAuth2!.call(this, 'eventbriteOAuth2Api', options);
} }
} catch (error) { } catch (error) {
throw new NodeApiError(this.getNode(), error); throw new NodeApiError(this.getNode(), error as JsonObject);
} }
} }