hngprojects / hng_boilerplate_nestjs

Description
Apache License 2.0
181 stars 105 forks source link

[FEAT] User Status Filtering for Organizations - BACKEND #95

Closed Laban254 closed 2 weeks ago

Laban254 commented 1 month ago

Description: Implement filtering for users in an organization based on their status (members, suspended, left workspace).

Acceptance Criteria:

  1. Filtering:

    • Implement server-side logic to handle filtering users by their status (members, suspended, left workspace).
  2. User Preferences:

    • Store user status details securely in the database.
    • Handle user-specific configurations and preferences related to the filtering process.
  3. Error Handling:

    • Log errors for invalid filter requests.
    • Display clear error messages for invalid inputs.
  4. Security Measures:

    • Use HTTPS for secure data transmission.
    • Validate user input on the server side.

Purpose: To filter users securely and efficiently, ensuring accurate and safe user management.

Requirements:

Expected Outcome:

Endpoints:

  1. Fetch Users in Organization:

    • Description: Provide a list of users based on filter criteria within a specific organization with pagination support.

    • Endpoint: GET /api/v1/organizations/{organization_id}/users

    • Request Headers:

      • Authorization: Bearer <token> (required)
      • Content-Type: application/json
      • Accept: application/json
    • Request Parameters:

      • status : string (values: members, suspended, left)
      • page: integer (optional, default: 1)
      • limit: integer (optional, default: 10)
    • Request Example:

      
           GET /api/v1/organizations/123/users?status=members&page=1&limit=10 HTTP/1.1
           Host: example.com
           Authorization: Bearer <token>
           Content-Type: application/json
           Accept: application/json
      
      **Response Example:**
    • Response (Success):

      • Status Code: 200 OK
      • Response Body:

        
           {
              "total": "integer",
              "page": "integer",
              "limit": "integer",
              "prev": "string or null",
              "next": "string or null",
              "users": [
                  {
                    "id": "String",
                    "email": "String",
                    "name": "String",
                    "role": "String",
                    "signup_type": "String",
                    "is_active": true,
                    "is_verified": true,
                    "created_at": "Date",
                    "updated_at": "Date",
                    "last_login_at": "Date",
                    "status": "String"
                 }
              ]
            }
    • Response (No Users Found):

      • Status Code: 404 Not Found
      • Response Body:

        
           {
          "message": "No users found",
          "statusCode": 404
          }
    • Response (Invalid Status):

      • Status Code: 400 Bad Request
      • Response Body:

        
        {
          "message": "Invalid status value",
          "statusCode": 400
        }
    • Response (Unauthorized):

      • Status Code: 401 Unauthorized
      • Response Body:

        
        {
          "message": "Unauthorized",
          "statusCode": 401
        }
    • Response (Internal Server Error):

      • Status Code: 500 Internal Server Error
      • Response Body:

        
        {
          "message": "Internal server error",
          "statusCode": 500
        }

Tasks:

Testing:

markessien commented 1 month ago

Duplicated

Laban254 commented 1 month ago

@markessien This issue continues from issue https://github.com/hngprojects/hng_boilerplate_nestjs/issues/66 which has been closed.

Laban254 commented 1 month ago

Team TechTitans slack id: @kibe - Python @KingTsonga - Java @Japhet Paul - PHP @EAZYLINK - Javascript @Cliff - c#

Laban254 commented 1 month ago

Hello @Popsicool @buka4rill,

I have completed the implementation for this issue and received the first approval. Could you please review and provide the second approval at your earliest convenience?

Thank you!

Popsicool commented 1 month ago

Your response should be an array of users in that organization not a single user.

Laban254 commented 1 month ago

It's okay, @Popsicool. I'm working on it.

Laban254 commented 1 month ago

@Popsicool Done

Popsicool commented 1 month ago

Alright, add pagination to it

Laban254 commented 1 month ago

@Popsicool I have added the pagination.

Popsicool commented 1 month ago

Add next and prev to your response

Laban254 commented 1 month ago

Okey

Laban254 commented 1 month ago

@Popsicool Done with adding next and prev to the response

Popsicool commented 1 month ago

cool