mirror of
https://github.com/zhigang1992/notion-api-worker.git
synced 2026-01-12 17:32:42 +08:00
fix: query collection API
This commit is contained in:
@@ -53,14 +53,24 @@ export const fetchPageById = async (pageId: string, notionToken?: string) => {
|
||||
};
|
||||
|
||||
const queryCollectionBody = {
|
||||
query: { aggregations: [{ property: "title", aggregator: "count" }] },
|
||||
loader: {
|
||||
type: "table",
|
||||
limit: 999,
|
||||
type: "reducer",
|
||||
reducers: {
|
||||
collection_group_results: {
|
||||
type: "results",
|
||||
limit: 999,
|
||||
loadContentCover: true,
|
||||
},
|
||||
"table:uncategorized:title:count": {
|
||||
type: "aggregation",
|
||||
aggregation: {
|
||||
property: "title",
|
||||
aggregator: "count",
|
||||
},
|
||||
},
|
||||
},
|
||||
searchQuery: "",
|
||||
userTimeZone: "Europe/Vienna",
|
||||
userLocale: "en",
|
||||
loadContentCover: true,
|
||||
},
|
||||
};
|
||||
|
||||
@@ -72,12 +82,17 @@ export const fetchTableData = async (
|
||||
const table = await fetchNotionData<CollectionData>({
|
||||
resource: "queryCollection",
|
||||
body: {
|
||||
collectionId,
|
||||
collectionViewId,
|
||||
collection: {
|
||||
id: collectionId,
|
||||
},
|
||||
collectionView: {
|
||||
id: collectionViewId,
|
||||
},
|
||||
...queryCollectionBody,
|
||||
},
|
||||
notionToken,
|
||||
});
|
||||
|
||||
return table;
|
||||
};
|
||||
|
||||
|
||||
@@ -165,7 +165,9 @@ export interface CollectionData {
|
||||
};
|
||||
};
|
||||
result: {
|
||||
blockIds: string[];
|
||||
reducerResults: {
|
||||
collection_group_results: { blockIds: string[] };
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -23,7 +23,7 @@ export const getTableData = async (
|
||||
const collectionRows = collection.value.schema;
|
||||
const collectionColKeys = Object.keys(collectionRows);
|
||||
|
||||
const tableArr: RowType[] = table.result.blockIds.map(
|
||||
const tableArr: RowType[] = table.result.reducerResults.collection_group_results.blockIds.map(
|
||||
(id: string) => table.recordMap.block[id]
|
||||
);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user