Skip to content

Commit

Permalink
Add pagination response fields to API requests that handle pagination.
Browse files Browse the repository at this point in the history
  • Loading branch information
Misterblue committed Nov 3, 2020
1 parent 1c51ba8 commit db36bcc
Show file tree
Hide file tree
Showing 10 changed files with 23 additions and 3 deletions.
2 changes: 2 additions & 0 deletions src/routes/api/v1/account/accountId/tokens.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ const procGetAccountTokens: RequestHandler = async (req: Request, resp: Response
req.vRestResp.Data = {
'tokens': toks
};

pager.addResponseFields(req);
};
next();
next();
Expand Down
8 changes: 5 additions & 3 deletions src/routes/api/v1/domains.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,19 +35,21 @@ import { Logger } from '@Tools/Logging';
const procGetDomains: RequestHandler = async (req: Request, resp: Response, next: NextFunction) => {
if (req.vAuthAccount) {

const pagination = new PaginationInfo();
const pager = new PaginationInfo();
const scoper = new AccountScopeFilter(req.vAuthAccount, "sponsorAccountId");

pagination.parametersFromRequest(req);
pager.parametersFromRequest(req);
scoper.parametersFromRequest(req);

const domainArray: any[] = [];
for await (const aDomain of Domains.enumerateAsync(scoper, pagination)) {
for await (const aDomain of Domains.enumerateAsync(scoper, pager)) {
domainArray.push( await buildDomainInfoV1(aDomain) );
};
req.vRestResp.Data = {
'domains': domainArray
};

pager.addResponseFields(req);
}
else {
req.vRestResp.respondFailure("Unauthorized");
Expand Down
2 changes: 2 additions & 0 deletions src/routes/api/v1/places.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ const procGetPlaces: RequestHandler = async (req: Request, resp: Response, next:
req.vRestResp.Data = {
'places': places
};

pager.addResponseFields(req);
}
else {
req.vRestResp.respondFailure('No account specified');
Expand Down
2 changes: 2 additions & 0 deletions src/routes/api/v1/places/placeId.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ const procGetPlaces: RequestHandler = async (req: Request, resp: Response, next:
req.vRestResp.Data = {
'places': allPlaces
};

pager.addResponseFields(req);
}
else {
req.vRestResp.respondFailure('unauthorized');
Expand Down
2 changes: 2 additions & 0 deletions src/routes/api/v1/requests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ const procGetRequests: RequestHandler = async (req: Request, resp: Response, nex
req.vRestResp.Data = {
requests: reqs
};

pager.addResponseFields(req);
}
else {
req.vRestResp.respondFailure('No account specified');
Expand Down
2 changes: 2 additions & 0 deletions src/routes/api/v1/tokens.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ const procGetTokens: RequestHandler = async (req: Request, resp: Response, next:
req.vRestResp.Data = {
tokens: toks
};

pager.addResponseFields(req);
}
else {
req.vRestResp.respondFailure('No account specified');
Expand Down
2 changes: 2 additions & 0 deletions src/routes/api/v1/user/connections.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ const procGetUserConnections: RequestHandler = async (req: Request, resp: Respon
req.vRestResp.Data = {
'connections': connections
};

pager.addResponseFields(req);
}
else {
req.vRestResp.respondFailure('unauthorized');
Expand Down
2 changes: 2 additions & 0 deletions src/routes/api/v1/user/friends.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ const procGetUserFriends: RequestHandler = async (req: Request, resp: Response,
req.vRestResp.Data = {
'friends': friends
};

pager.addResponseFields(req);
}
else {
req.vRestResp.respondFailure('unauthorized');
Expand Down
2 changes: 2 additions & 0 deletions src/routes/api/v1/user/places.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ const procGetPlaces: RequestHandler = async (req: Request, resp: Response, next:
req.vRestResp.Data = {
'places': allPlaces
};

pager.addResponseFields(req);
}
else {
req.vRestResp.respondFailure('unauthorized');
Expand Down
2 changes: 2 additions & 0 deletions src/routes/api/v1/users.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ const procGetUsers: RequestHandler = async (req: Request, resp: Response, next:
req.vRestResp.Data = {
users: accts
};

pager.addResponseFields(req);
}
else {
req.vRestResp.respondFailure('No account specified');
Expand Down

0 comments on commit db36bcc

Please sign in to comment.