🐛 Fix bug paginating databases and users (#1907)

This commit is contained in:
Ricardo Espinoza 2021-06-22 17:59:04 -04:00 committed by GitHub
parent c21c8b3369
commit 92a2e863f3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 4 deletions

View file

@ -52,6 +52,8 @@ export async function notionApiRequest(this: IHookFunctions | IExecuteFunctions
export async function notionApiRequestAllItems(this: IExecuteFunctions | ILoadOptionsFunctions | IPollFunctions, propertyName: string, method: string, endpoint: string, body: any = {}, query: IDataObject = {}): Promise<any> { // tslint:disable-line:no-any
const resource = this.getNodeParameter('resource', 0) as string;
const returnData: IDataObject[] = [];
let responseData;
@ -59,8 +61,11 @@ export async function notionApiRequestAllItems(this: IExecuteFunctions | ILoadOp
do {
responseData = await notionApiRequest.call(this, method, endpoint, body, query);
const { next_cursor } = responseData;
query['start_cursor'] = next_cursor;
body['start_cursor'] = next_cursor;
if (resource === 'block' || resource === 'user') {
query['start_cursor'] = next_cursor;
} else {
body['start_cursor'] = next_cursor;
}
returnData.push.apply(returnData, responseData[propertyName]);
if (query.limit && query.limit <= returnData.length) {
return returnData;

View file

@ -47,7 +47,6 @@ import {
databasePageFields,
databasePageOperations,
} from './DatabasePageDescription';
import { getServers } from 'dns';
export class Notion implements INodeType {
description: INodeTypeDescription = {
@ -323,7 +322,6 @@ export class Notion implements INodeType {
if (operation === 'getAll') {
for (let i = 0; i < length; i++) {
const body: IDataObject = {
page_size: 100,
filter: { property: 'object', value: 'database' },
};
const returnAll = this.getNodeParameter('returnAll', i) as boolean;