def get_users()

in components/user_management/src/routes/user.py [0:0]


def get_users(user_type: Optional[str] = None,
              skip: int = Query(0, ge=0, le=2000),
              limit: int = Query(10, ge=1, le=100),
              user_group: Optional[str] = None,
              fetch_tree: Optional[bool] = False,
              status: Optional[str] = None,
              sort_by: Optional[Literal["first_name", "last_name",
              "email", "created_time"]] = "created_time",
              sort_order: Optional[Literal["ascending", "descending"]] =
              "descending"):
  """The get users endpoint will return an array users from
  firestore

  ### Args:
      skip (int): Number of objects to be skipped
      limit (int): Size of user array to be returned
      user_group (str): To fetch the User belong to given group
      fetch_tree (bool): To fetch the entire
      object instead of the UUID of the object
      status (str): To fetch the user having given status (action or inactive)
      user_type (str): Type of the user example: faculty or learner etc.
      sort_by (str): sorting field name
      sort_order (str): ascending / descending

  ### Raises:
      Exception: 500 Internal Server Error if something went wrong

  ### Returns:
      AllUserResponseModel: Array of User Object
  """
  try:
    collection_manager = User.collection.filter("is_deleted", "==", False)
    if user_type:
      collection_manager = collection_manager.filter("user_type", "==",
                                                     user_type)
    if user_group:
      collection_manager = collection_manager.filter("user_groups",
                                                     "array_contains",
                                                     user_group)
    if status is not None:
      collection_manager = collection_manager.filter("status", "==", status)

    total_users = collection_manager.fetch()
    count = 0
    for idx, i in enumerate(total_users):
      count = idx + 1

    users = collection_sorting(collection_manager=collection_manager,
                               sort_by=sort_by, sort_order=sort_order,
                               skip=skip, limit=limit)
    if fetch_tree:
      users = [
        CollectionHandler.loads_field_data_from_collection(
          i.get_fields(reformat_datetime=True)) for i in users
      ]
    else:
      users = [i.get_fields(reformat_datetime=True) for i in users]

    response = {"records": users, "total_count": count}

    return {
        "success": True,
        "message": "Data fetched successfully",
        "data": response
    }
  except ValidationError as e:
    Logger.error(e)
    Logger.error(traceback.print_exc())
    raise BadRequest(str(e)) from e
  except Exception as e:
    Logger.error(e)
    Logger.error(traceback.print_exc())
    raise InternalServerError(str(e)) from e