Admin Dashboard Backend (Phases 1-4) #5

Merged
stephen merged 9 commits from admin into main 2026-01-22 14:11:43 -07:00
Owner
No description provided.
stephen added 5 commits 2026-01-22 13:37:19 -07:00
- Configure Jest with mongodb-memory-server for isolated testing
- Add phase 1-4 test suites covering all admin requirements
- Add test helpers and setup/teardown utilities
- Install jest, supertest, mongodb-memory-server dependencies
- Add database indexes for admin queries (role, isActive+role, createdAt, lastLoginAt)
- Update setUserActive to track disabledAt and disabledBy fields
- Add getPaginatedUsers function with search, filter, sort support
- Add updateUserRole function for promoting/demoting users
- Create admin routes with full user management API:
  - GET /api/admin/users - paginated list with search/filter/sort
  - GET /api/admin/users/:id - user details with recent activity
  - PATCH /api/admin/users/:id - enable/disable users
  - PATCH /api/admin/users/:id/role - promote/demote users
- Add validation for ObjectId format and self-modification prevention
- All 53 Phase 1 backend tests passing
- Add GET /api/admin/activity with pagination and filters
- Add GET /api/admin/users/:id/activity for user-specific history
- Add GET /api/admin/activity/export for CSV export
- Implement $lookup aggregation for user info (name, email)
- Add date range filtering with validation
- Export limited to 10,000 records with truncation headers
- All 50 Phase 2 tests passing
- Add GET /api/admin/stats/overview (user counts, login stats)
- Add GET /api/admin/stats/active-users (time series with period toggle)
- Add GET /api/admin/stats/actions (action breakdown with date filter)
- Add GET /api/admin/stats/peak-times (hourly/daily averages)
- Implement 5-minute in-memory caching for expensive aggregations
- All 57 Phase 3 tests passing
- Add GET /api/admin/settings for configuration retrieval
- Add PATCH /api/admin/settings with validation (30-365 days)
- Implement TTL index update when retention period changes
- Add last admin protection (cannot demote last active admin)
- Add audit logging for admin actions (ADMIN_UPDATE_SETTINGS, etc.)
- 45/52 Phase 4 tests passing (7 rate limiting tests not in scope)
stephen added 1 commit 2026-01-22 13:52:39 -07:00
Traefik strips the /api prefix before forwarding requests to the backend,
so /api/admin requests arrive as /admin. Changed route mounting from
/api/admin to /admin to match the actual incoming request path.
stephen added 1 commit 2026-01-22 13:57:04 -07:00
Wrap getPaginatedUsers result in { data: result } to match the project
convention and frontend code that expects response.data.users.
stephen added 1 commit 2026-01-22 13:58:59 -07:00
Wrap user detail response in { data: { user } } to match frontend expectation.
stephen added 1 commit 2026-01-22 14:01:20 -07:00
Wrap all admin endpoint responses in { data: ... } to match frontend
expectations and project conventions:
- PATCH /users/:id (enable/disable)
- PATCH /users/:id/role (promote/demote)
- GET /users/:id/activity
- GET /activity
- PATCH /settings
stephen merged commit 81e5682ab1 into main 2026-01-22 14:11:43 -07:00
Sign in to join this conversation.
No Reviewers
No Label
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: stephen/apartment-dashboard-api#5
No description provided.