Skip to content

Commit

Permalink
Merge pull request #2068 from Real-Dev-Squad/yash/user-role
Browse files Browse the repository at this point in the history
add roles query param in /users api to get all members
  • Loading branch information
iamitprakash authored Aug 17, 2024
2 parents 72d8f08 + d80690d commit b478da6
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
1 change: 1 addition & 0 deletions controllers/users.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ const getUsers = async (req, res) => {
user,
});
}

if (!transformedQuery?.days && transformedQuery?.filterBy === "unmerged_prs") {
return res.boom.badRequest(`Days is required for filterBy ${transformedQuery?.filterBy}`);
}
Expand Down
7 changes: 7 additions & 0 deletions middlewares/validators/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,13 @@ async function getUsers(req, res, next) {
filterBy: joi.string().optional(),
days: joi.string().optional(),
dev: joi.string().optional(),
roles: joi.optional().custom((value, helpers) => {
if (value !== "member") {
return helpers.message("only member role is supported");
}

return value;
}),
});
try {
await schema.validateAsync(req.query);
Expand Down
14 changes: 13 additions & 1 deletion models/users.js
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,19 @@ const fetchPaginatedUsers = async (query) => {
const size = parseInt(query.size) || 100;
const doc = (query.next || query.prev) && (await userModel.doc(query.next || query.prev).get());

let dbQuery = userModel.where("roles.archived", "==", false).orderBy("username");
let dbQuery;
/**
* !!NOTE : At the time of writing we only support member in the role query
* this will get fixed with the new onboarding flow, contact @tejaskh3 for more info
*
* if you're making changes to this code remove the archived check in the role query, example: role=archived,member
*/
if (query.roles === "member") {
dbQuery = userModel.where("roles.archived", "==", false).where("roles.member", "==", true);
} else {
dbQuery = userModel.where("roles.archived", "==", false).orderBy("username");
}

let compositeQuery = [dbQuery];
if (isDevMode) {
const usernameQuery = userModel.where("roles.archived", "==", false).orderBy("username");
Expand Down

0 comments on commit b478da6

Please sign in to comment.