diff --git a/controllers/users.js b/controllers/users.js index b04fe85ca..858212fa4 100644 --- a/controllers/users.js +++ b/controllers/users.js @@ -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}`); } diff --git a/middlewares/validators/user.js b/middlewares/validators/user.js index 8be954e2e..387591d8b 100644 --- a/middlewares/validators/user.js +++ b/middlewares/validators/user.js @@ -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); diff --git a/models/users.js b/models/users.js index 087e18a9e..9c7b0c342 100644 --- a/models/users.js +++ b/models/users.js @@ -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");