RealDevSquad / RealDevSquad/website-backend

[RFC] filter users based on roles

Open
#1,593 8 comments 0 reactions 1 assignee View on GitHub

@anishpawaskar is already working on this.

Since Oct 7, 2023.

backend
Dominant language
JavaScript
Stars
74
Forks
276
Avg merge
1d 26m
Merged PRs (30d)
14

Description

Why we are making this change?

  • We are planning to deprecate the /members API because naming convention is not right and it is returning the wrong data it should return members but it’s returning all the users as well as members.

What is change?

  • We are planning to use /users API instead of using /members.
  • We are planning to add role and include query in /users to filter out users based on role. if any user have a role member=true and include=true then it should returns all the users who have role member as true.
  • We are planning to add one more query include=true or include=false based on this users will filter out.
    For ex:
    • If someone hits this route /users?role=member&include=true then it should returns all the users who have role member as true.
    • If someone hits this route /users?role=member&include=false then it should returns all the users who have role member as false.

Filter users using multiple roles:

  • If we try to pass multiple roles in role query then the response should be paginated.
    For eg:
    • If someone hits this route /users?role=member,maven&include=true then it should return users who have role maven or member as true.
    • If someone hits this route /users?role=member,maven&include=false then it should return users who have role maven or member as false.

Issue:

  • While querying over database if a particular field does not exist in document then it exclude documents where the given field does not exist.
  • As of now in our users data the member field is only available in users who are member.
  • So if we try to query over users who don't have member field that users will be skipped.

Possible solutions:

  1. I will make a script which can add member field in users who don't have it. So it makes possible to query over database.
  2. We can filter out users like how we are doing it on front-end. Like we get all users and then we can check that user have member field or not if not then we will push that users in array then we will return it in response.

Queries:

  1. ?q=role:member+role:maven+-role:admin
    queryParser: https://replit.com/@AimBhai/praksh-query-filter
  2. ?q=roleInclude:member,developer+roleExclude:maven+incompleteUserDetails:true
    queryParser: https://replit.com/@AimBhai/vinayak-query-filter#index.js
  3. ?q=role%3Amember+role%3AAmaven+value%3Afalse
    queryParser: https://replit.com/@AimBhai/filter-users-based-on-role#index.js

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.