Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update list managers (v2) #301

Merged
merged 3 commits into from
Jun 2, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 31 additions & 9 deletions packages/api/src/controllers/v2/community/details.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,34 @@ class CommunityController {
}

getManagers = (req: Request, res: Response) => {
const { filterByActive } = req.query;
let active: boolean | undefined;
if (filterByActive === 'true') {
active = true;
} else if (filterByActive === 'false') {
active = false;
const community = req.params.id;
let { state, offset, limit, search, orderBy } = req.query;
if (state === undefined || typeof state !== 'string') {
state = undefined;
}
if (offset === undefined || typeof offset !== 'string') {
offset = '0';
}
if (limit === undefined || typeof limit !== 'string') {
limit = '5';
}
if (orderBy === undefined || typeof orderBy !== 'string') {
orderBy = undefined;
}

this.detailsService
.getManagers(parseInt(req.params.id, 10), active)
.listManagers(
parseInt(community, 10),
parseInt(offset, 10),
parseInt(limit, 10),
{
state,
},
search !== undefined && typeof search === 'string'
? search
: undefined,
orderBy
)
.then((r) => standardResponse(res, 200, true, r))
.catch((e) => standardResponse(res, 400, false, '', { error: e }));
};
Expand Down Expand Up @@ -78,7 +96,7 @@ class CommunityController {
search !== undefined && typeof search === 'string'
? search
: undefined,
orderBy,
orderBy
)
.then((r) => standardResponse(res, 200, true, r))
.catch((e) => standardResponse(res, 400, false, '', { error: e }));
Expand Down Expand Up @@ -122,7 +140,11 @@ class CommunityController {
return;
}
this.detailsService
.count(groupBy as string, status as string, excludeCountry as string)
.count(
groupBy as string,
status as string,
excludeCountry as string
)
.then((r) => standardResponse(res, 200, true, r))
.catch((e) => standardResponse(res, 400, false, '', { error: e }));
};
Expand Down
35 changes: 27 additions & 8 deletions packages/api/src/routes/v2/community/details.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,17 +67,36 @@ export default (route: Router): void => {
* summary: Get community managers
* parameters:
* - in: query
* name: filterByActive
* name: state
* schema:
* type: boolean
* type: string
* enum: [active, removed]
* required: false
* description: filter by active/inactive/both (if filterByActive = undefined return both)
* - in: path
* name: id
* description: manager state
* - in: query
* name: offset
* schema:
* type: integer
* required: true
* description: community id
* required: false
* description: offset used for community pagination (default 0)
* - in: query
* name: limit
* schema:
* type: integer
* required: false
* description: limit used for community pagination (default 5)
* - in: query
* name: search
* schema:
* type: string
* required: false
* description: search by address or username
* - in: query
* name: orderBy
* schema:
* type: string
* required: false
* description: order key and order direction separated by colon (since:desc)
* responses:
* "200":
* description: OK
Expand Down Expand Up @@ -136,7 +155,7 @@ export default (route: Router): void => {
* schema:
* $ref: '#/components/schemas/UbiCommunityContract'
*/
route.get('/:id/ambassador', controller.getAmbassador);
route.get('/:id/ambassador', controller.getAmbassador);

/**
* @swagger
Expand Down
3 changes: 2 additions & 1 deletion packages/core/src/services/endpoints.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@ export interface IListBeneficiary {
firstName?: string | null;
lastName?: string | null;
avatarMediaPath?: string | null;
timestamp: number;
timestamp?: number;
since?: number;
claimed: string;
blocked: boolean;
// to users not yet registered, the values below do not exist
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/services/ubi/community.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ import {
getCommunityProposal,
getClaimed,
getCommunityState,
getCommunityManagers,
} from '../../subgraph/queries/community';
import { getCommunityManagers } from '../../subgraph/queries/manager';
import { BaseError } from '../../utils/baseError';
import { fetchData } from '../../utils/dataFetching';
import { createThumbnailUrl, notifyManagerAdded } from '../../utils/util';
Expand Down
Loading