Skip to content

Commit

Permalink
Merge pull request #61 from pbteja1998/fix-query-collection-api
Browse files Browse the repository at this point in the history
fix: query collection API
  • Loading branch information
tobiaslins authored Oct 6, 2021
2 parents 882d36e + aa169aa commit 8b93b03
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 9 deletions.
29 changes: 22 additions & 7 deletions src/api/notion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
};

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

Expand Down
4 changes: 3 additions & 1 deletion src/api/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,9 @@ export interface CollectionData {
};
};
result: {
blockIds: string[];
reducerResults: {
collection_group_results: { blockIds: string[] };
};
};
}

Expand Down
2 changes: 1 addition & 1 deletion src/routes/table.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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]
);

Expand Down

0 comments on commit 8b93b03

Please sign in to comment.