From 69a1f8af00f6bd64795c709fd25e407cfc28c0e5 Mon Sep 17 00:00:00 2001 From: shraddha shaligram Date: Tue, 23 Jun 2020 20:29:47 -0700 Subject: [PATCH] fix pagination --- .../credentials/ZoomOAuth2Api.credentials.ts | 16 ++++---------- .../nodes-base/nodes/Zoom/GenericFunctions.ts | 18 ++++++++++----- .../nodes/Zoom/MeetingDescription.ts | 22 +++++++++---------- .../Zoom/MeetingRegistrantDescription.ts | 16 +++++++------- .../nodes/Zoom/WebinarDescription.ts | 14 ++++++------ packages/nodes-base/nodes/Zoom/Zoom.node.ts | 16 ++++++++++---- 6 files changed, 55 insertions(+), 47 deletions(-) diff --git a/packages/nodes-base/credentials/ZoomOAuth2Api.credentials.ts b/packages/nodes-base/credentials/ZoomOAuth2Api.credentials.ts index c00c694661..f85cc75254 100644 --- a/packages/nodes-base/credentials/ZoomOAuth2Api.credentials.ts +++ b/packages/nodes-base/credentials/ZoomOAuth2Api.credentials.ts @@ -1,14 +1,7 @@ -import { ICredentialType, NodePropertyTypes } from 'n8n-workflow'; - -const userScopes = [ - 'meeting:read', - 'meeting:write', - 'user:read', - 'user:write', - 'user_profile', - 'webinar:read', - 'webinar:write' -]; +import { + ICredentialType, + NodePropertyTypes, +} from 'n8n-workflow'; export class ZoomOAuth2Api implements ICredentialType { name = 'zoomOAuth2Api'; @@ -27,7 +20,6 @@ export class ZoomOAuth2Api implements ICredentialType { type: 'hidden' as NodePropertyTypes, default: 'https://zoom.us/oauth/token' }, - { displayName: 'Scope', name: 'scope', diff --git a/packages/nodes-base/nodes/Zoom/GenericFunctions.ts b/packages/nodes-base/nodes/Zoom/GenericFunctions.ts index 500b0a64d9..6a8593e3ab 100644 --- a/packages/nodes-base/nodes/Zoom/GenericFunctions.ts +++ b/packages/nodes-base/nodes/Zoom/GenericFunctions.ts @@ -75,6 +75,7 @@ export async function zoomApiRequestAllItems( // tslint:disable-line:no-any const returnData: IDataObject[] = []; let responseData; + query.page_number = 0; do { responseData = await zoomApiRequest.call( this, @@ -83,14 +84,21 @@ export async function zoomApiRequestAllItems( body, query ); - query.page_number = responseData['page_number']; + query.page_number++; returnData.push.apply(returnData, responseData[propertyName]); + // zoom free plan rate limit is 1 request/second + // TODO just wait when the plan is free + await wait(); } while ( - responseData['page_number'] !== undefined && - responseData['page_number'] !== '' + responseData.page_count !== responseData.page_number ); return returnData; } - - +function wait() { + return new Promise((resolve, reject) => { + setTimeout(() => { + resolve(true); + }, 1000); + }); +} diff --git a/packages/nodes-base/nodes/Zoom/MeetingDescription.ts b/packages/nodes-base/nodes/Zoom/MeetingDescription.ts index 829418d12b..5a8a5966a9 100644 --- a/packages/nodes-base/nodes/Zoom/MeetingDescription.ts +++ b/packages/nodes-base/nodes/Zoom/MeetingDescription.ts @@ -39,7 +39,7 @@ export const meetingOperations = [ name: 'Update', value: 'update', description: 'Update a meeting', - } + }, ], default: 'create', description: 'The operation to perform.', @@ -69,7 +69,7 @@ export const meetingFields = [ description: 'User ID or email address of user.', }, { - displayName: 'Additional settings', + displayName: 'Additional fields', name: 'additionalFields', type: 'collection', placeholder: 'Add Field', @@ -83,7 +83,7 @@ export const meetingFields = [ resource: [ 'meeting', ], - } + }, }, options: [ { @@ -209,7 +209,7 @@ export const meetingFields = [ ], default: 2, - description: 'Meeting type.' + description: 'Meeting type.', }, { displayName: 'Muting before entry', @@ -219,7 +219,7 @@ export const meetingFields = [ description: 'Mute participants upon entry.', }, { - displayName: 'Participant Video', + displayName: 'Participant video', name: 'participant_video', type: 'boolean', default: false, @@ -308,7 +308,7 @@ export const meetingFields = [ description: 'Meeting ID.', }, { - displayName: 'Additional settings', + displayName: 'Additional fields', name: 'additionalFields', type: 'collection', placeholder: 'Add Field', @@ -398,13 +398,13 @@ export const meetingFields = [ }, typeOptions: { minValue: 1, - maxValue: 300 + maxValue: 300, }, default: 30, description: 'How many results to return.', }, { - displayName: 'Additional settings', + displayName: 'Additional fields', name: 'additionalFields', type: 'collection', placeholder: 'Add Field', @@ -456,7 +456,7 @@ export const meetingFields = [ displayOptions: { show: { operation: [ - 'delete' + 'delete', ], resource: [ 'meeting', @@ -521,7 +521,7 @@ export const meetingFields = [ description: 'Meeting ID.', }, { - displayName: 'Additional settings', + displayName: 'Additional fields', name: 'additionalFields', type: 'collection', placeholder: 'Add Field', @@ -667,7 +667,7 @@ export const meetingFields = [ ], default: 2, - description: 'Meeting type.' + description: 'Meeting type.', }, { displayName: 'Muting before entry', diff --git a/packages/nodes-base/nodes/Zoom/MeetingRegistrantDescription.ts b/packages/nodes-base/nodes/Zoom/MeetingRegistrantDescription.ts index b9a5147364..b7e5271f55 100644 --- a/packages/nodes-base/nodes/Zoom/MeetingRegistrantDescription.ts +++ b/packages/nodes-base/nodes/Zoom/MeetingRegistrantDescription.ts @@ -95,7 +95,7 @@ export const meetingRegistrantFields = [ description: 'First Name.', }, { - displayName: 'Additional settings', + displayName: 'Additional fields', name: 'additionalFields', type: 'collection', placeholder: 'Add Field', @@ -109,7 +109,7 @@ export const meetingRegistrantFields = [ resource: [ 'meetingRegistrants', ], - } + }, }, options: [ { @@ -202,7 +202,7 @@ export const meetingRegistrantFields = [ }, ], default: '', - description: 'Meeting type.' + description: 'Meeting type.', }, { displayName: 'Role in purchase process', @@ -228,7 +228,7 @@ export const meetingRegistrantFields = [ ], default: '', - description: 'Role in purchase process.' + description: 'Role in purchase process.', }, { displayName: 'State', @@ -304,13 +304,13 @@ export const meetingRegistrantFields = [ }, typeOptions: { minValue: 1, - maxValue: 300 + maxValue: 300, }, default: 30, description: 'How many results to return.', }, { - displayName: 'Additional settings', + displayName: 'Additional fields', name: 'additionalFields', type: 'collection', placeholder: 'Add Field', @@ -324,7 +324,7 @@ export const meetingRegistrantFields = [ resource: [ 'meetingRegistrants', ], - } + }, }, options: [ { @@ -412,7 +412,7 @@ export const meetingRegistrantFields = [ description: `Registrant Status.`, }, { - displayName: 'Additional settings', + displayName: 'Additional fields', name: 'additionalFields', type: 'collection', placeholder: 'Add Field', diff --git a/packages/nodes-base/nodes/Zoom/WebinarDescription.ts b/packages/nodes-base/nodes/Zoom/WebinarDescription.ts index 19796ea51a..228cf9f1ae 100644 --- a/packages/nodes-base/nodes/Zoom/WebinarDescription.ts +++ b/packages/nodes-base/nodes/Zoom/WebinarDescription.ts @@ -69,7 +69,7 @@ export const webinarFields = [ description: 'User ID or email address of user.', }, { - displayName: 'Additional settings', + displayName: 'Additional fields', name: 'additionalFields', type: 'collection', placeholder: 'Add Field', @@ -263,7 +263,7 @@ export const webinarFields = [ }, ], default: 5, - description: 'Webinar type.' + description: 'Webinar type.', }, ], @@ -290,7 +290,7 @@ export const webinarFields = [ description: 'Webinar ID.', }, { - displayName: 'Additional settings', + displayName: 'Additional fields', name: 'additionalFields', type: 'collection', placeholder: 'Add Field', @@ -380,7 +380,7 @@ export const webinarFields = [ }, typeOptions: { minValue: 1, - maxValue: 300 + maxValue: 300, }, default: 30, description: 'How many results to return.', @@ -397,7 +397,7 @@ export const webinarFields = [ displayOptions: { show: { operation: [ - 'delete' + 'delete', ], resource: [ 'webinarId', @@ -456,7 +456,7 @@ export const webinarFields = [ description: 'User ID or email address of user.', }, { - displayName: 'Additional settings', + displayName: 'Additional fields', name: 'additionalFields', type: 'collection', placeholder: 'Add Field', @@ -470,7 +470,7 @@ export const webinarFields = [ resource: [ 'webinar', ], - } + }, }, options: [ { diff --git a/packages/nodes-base/nodes/Zoom/Zoom.node.ts b/packages/nodes-base/nodes/Zoom/Zoom.node.ts index 56901ac2ce..18e3614cc4 100644 --- a/packages/nodes-base/nodes/Zoom/Zoom.node.ts +++ b/packages/nodes-base/nodes/Zoom/Zoom.node.ts @@ -203,13 +203,21 @@ export class Zoom implements INodeType { //https://marketplace.zoom.us/docs/api-reference/zoom-api/meetings/meetings const userId = this.getNodeParameter('userId', i) as string; const returnAll = this.getNodeParameter('returnAll', i) as boolean; + + const additionalFields = this.getNodeParameter( + 'additionalFields', + i + ) as IDataObject; + if (additionalFields.type) { + qs.type = additionalFields.type as string; + + } if (returnAll) { - responseData = await zoomApiRequestAllItems.call(this, 'results', 'GET', `/users/${userId}/meetings`, {}, qs); + responseData = await zoomApiRequestAllItems.call(this, 'meetings', 'GET', `/users/${userId}/meetings`, {}, qs); } else { - const limit = this.getNodeParameter('limit', i) as number; - qs.page_size = limit; + qs.page_size = this.getNodeParameter('limit', i) as number;; responseData = await zoomApiRequest.call(this, 'GET', `/users/${userId}/meetings`, {}, qs); - responseData = responseData.results; + } }