A comprehensive admin user management module built with NestJS, featuring user control, audit logging, and role-based access control.
✅ View users with pagination ✅ Search and filter users by email, name, role, and status ✅ Suspend/activate user accounts ✅ Change user roles (USER, ADMIN, MODERATOR) ✅ Reset user passwords ✅ Complete audit logging for all admin actions ✅ Role-based access control (Admin only) ✅ Comprehensive unit and E2E tests
npm install- Create a PostgreSQL database
- Copy
.env.exampleto.envand configure your database credentials
cp .env.example .env# Development
npm run start:dev
# Production
npm run build
npm run start# Unit tests
npm test
# E2E tests
npm run test:e2e
# Test coverage
npm run test:covAll endpoints require admin authentication via JWT Bearer token.
GET /admin/users?page=1&limit=10&search=john&role=user&status=active
GET /admin/users/:id
PATCH /admin/users/:id/role
Body: { "role": "admin" }
PATCH /admin/users/:id/status
Body: { "status": "suspended" }
POST /admin/users/:id/reset-password
Body: { "newPassword": "newPassword123" }
GET /admin/users/:id/audit-logs?page=1&limit=10
user- Regular usermoderator- Moderator with elevated permissionsadmin- Full administrative access
active- User can access the systemsuspended- User is blocked from accessing the system
All admin actions are automatically logged with:
- Action type (role_changed, user_suspended, etc.)
- Target user
- Admin who performed the action
- Metadata (old/new values)
- Timestamp
- Entities: User, AuditLog
- DTOs: Query validation and transformation
- Guards: JWT authentication and role-based authorization
- Service: Business logic and database operations
- Controller: REST API endpoints
The module includes comprehensive tests:
- Unit tests for service and controller
- E2E tests for all endpoints
- Test coverage for all features
All tests pass including CI/CD pipeline requirements.