Skip to content

Commit

Permalink
Merge pull request #148 from metagov/feat/boardroom
Browse files Browse the repository at this point in the history
feat: make boardroom pageable.
  • Loading branch information
crazyyuan authored Sep 7, 2023
2 parents c4780ac + 0709141 commit 0e5061b
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions Implementations/API/backend/functions/boardroom/getMembers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ export const handler: APIGatewayProxyHandlerV2 = async (event) => {
const name = event?.pathParameters?.id;
if (!name) return { statusCode: 400, message: "Missing name" };

const cursor: string | undefined = event?.queryStringParameters?.cursor;

const template = {
"@context": {
"@vocab": "http://daostar.org/",
Expand All @@ -33,14 +35,17 @@ export const handler: APIGatewayProxyHandlerV2 = async (event) => {
name: name,
};

const queryPath =
let queryPath =
path + "/" + name + "/voters" + "?limit=50&key=" + BoardroomKey;
if (cursor) {
queryPath += "&cursor=" + decodeURIComponent(cursor);
}

console.log("queryPath:", queryPath);
const res = (await apiRequest(queryPath, "GET")) as any;

if (!res.data) return { statusCode: 404, message: "DAO not found" };
const voters = res.data;
const nextCursor = res.nextCursor;

const membersFormatted = voters.map((a: any) => {
return {
Expand All @@ -49,7 +54,11 @@ export const handler: APIGatewayProxyHandlerV2 = async (event) => {
};
});

const transformed = { members: membersFormatted, ...template };
const transformed = {
members: membersFormatted,
...template,
nextCursor: encodeURIComponent(nextCursor),
};

return transformed
? {
Expand Down

0 comments on commit 0e5061b

Please sign in to comment.