fix: query collection API

This commit is contained in:
Bhanu Teja Pachipulusu
2021-10-06 12:08:24 +05:30
parent 882d36ebbd
commit aa169aa3e6
3 changed files with 26 additions and 9 deletions

View File

@@ -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;
};

View File

@@ -165,7 +165,9 @@ export interface CollectionData {
};
};
result: {
blockIds: string[];
reducerResults: {
collection_group_results: { blockIds: string[] };
};
};
}

View File

@@ -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]
);