mirror of
https://github.com/n8n-io/n8n.git
synced 2024-12-26 21:19:43 -08:00
d9b98fc8be
* ✨ Create rule `no-unneeded-backticks` * 👕 Enable rule * ⚡ Run rule on `cli` * ⚡ Run rule on `core` * ⚡ Run rule on `workflow` * ⚡ Rule rule on `design-system` * ⚡ Run rule on `node-dev` * ⚡ Run rule on `editor-ui` * ⚡ Run rule on `nodes-base`
38 lines
980 B
TypeScript
38 lines
980 B
TypeScript
import {
|
|
IDataObject,
|
|
ILoadOptionsFunctions,
|
|
INodeListSearchItems,
|
|
INodeListSearchResult,
|
|
} from 'n8n-workflow';
|
|
import { notionApiRequestAllItems } from './GenericFunctions';
|
|
|
|
export async function getDatabases(
|
|
this: ILoadOptionsFunctions,
|
|
filter?: string,
|
|
): Promise<INodeListSearchResult> {
|
|
const returnData: INodeListSearchItems[] = [];
|
|
const body: IDataObject = {
|
|
page_size: 100,
|
|
query: filter,
|
|
filter: { property: 'object', value: 'database' },
|
|
};
|
|
const databases = await notionApiRequestAllItems.call(this, 'results', 'POST', '/search', body);
|
|
for (const database of databases) {
|
|
returnData.push({
|
|
name: database.title[0]?.plain_text || database.id,
|
|
value: database.id,
|
|
url: database.url,
|
|
});
|
|
}
|
|
returnData.sort((a, b) => {
|
|
if (a.name.toLocaleLowerCase() < b.name.toLocaleLowerCase()) {
|
|
return -1;
|
|
}
|
|
if (a.name.toLocaleLowerCase() > b.name.toLocaleLowerCase()) {
|
|
return 1;
|
|
}
|
|
return 0;
|
|
});
|
|
return { results: returnData };
|
|
}
|