NexGenStudioDev / NexGenStudioDev/Ciitm-Backend

Implement Backend APIs to Manage Admin Roles (Get All Admins & Delete Admin Role)

Open
#59 5 comments 0 reactions 1 assignee View on GitHub

@plk449 is already working on this.

Since Aug 27, 2025.

API auth backend enhancement good first issue onlydust-wave
Dominant language
JavaScript
Stars
1
Forks
17
PR merge metrics
No merged PRs in 30d

Description

Extend the backend to support Admin role management by adding secure APIs that allow:

  • ✅ Fetching all users with the Admin role
  • ❌ Revoking the Admin role from a user by email

These APIs are essential for supporting the Admin Role Management Page on the frontend, allowing Admins to view and manage other Admin users in the system.

📝 Description

Add two new endpoints to manage Admin roles:

  1. GET /api/v1/role/admins

    • Returns a list of all users who currently have the Admin role.
    • Response should include each user’s name and email.
  2. DELETE /api/v1/role/admin/:email

    • Removes the Admin role from a user based on their email address.
    • Should respond with a success message or an appropriate error if the user is not found or not an Admin.

📌 Objectives

  • ✅ Create the following endpoints:
GET    /api/v1/role/admins         → Fetch all Admin users
DELETE /api/v1/role/admin/:email   → Remove Admin role by email
  • ✅ Ensure responses include relevant messages and handle common errors (e.g. user not found, already not an Admin, etc.).

1️⃣ Get All Admins

GET /api/v1/role/admins

Expected Response
{
  "status": 200,
  "message": "Admins fetched successfully",
  "data": [
    {
      "name": "Jane Doe",
      "email": "jane@example.com",
      "role": "admin"
    },
    ...
  ]
}

2️⃣ Delete Admin Role by Email


DELETE /api/v1/role/admin/:email

Expected Response

{
  "status": 200,
  "message": "Admin role revoked successfully",
  "data": {
    "email": "target@example.com"
  }
}


✅ Acceptance Criteria

To ensure the Admin Role Management backend APIs are implemented correctly, the following criteria must be met:

  • 📄 GET /api/v1/role/admins

    • Returns all users with the Admin role.
    • Each user object includes required fields: name, email, and optionally user ID.
  • DELETE /api/v1/role/admin/:email

    • Successfully removes the Admin role for the user with the given email (if valid).
    • Returns a clear success or error message.
  • 🔐 Access Control & Validation

    • Both routes are protected using AuthMiddleware.Admin.
    • Only authenticated Admin users can access these routes.
    • Email is validated before attempting to revoke a role.
    • Prevent errors when email does not exist or user is not an Admin.
  • ⚠️ Error Handling

    • Handles invalid inputs, unauthorized access, and unexpected server errors gracefully.
    • Proper HTTP status codes are returned (e.g. 200, 400, 403, 404, 500).
  • 🧪 Testing

    • Unit tests written (if a testing framework like Jest, Mocha, etc., is set up).
    • Tests cover both success and failure cases.
  • 📦 Response Format

    • All responses use the standard response utility:
      • SendResponse.success() for successful responses.
      • SendResponse.error() for error handling.

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.