feat: admin API endpoints for users, config, devices, and system monitoring (closes #11) - #33
Merged
KarenZita01 merged 4 commits intoJul 29, 2026
Conversation
…quipChain#11) - src/middleware/auth.js: minimal JWT authenticate middleware. Issue EquipChain#11 says admin routes depend on auth work from "Issue EquipChain#5", but EquipChain#5 is actually about testing infrastructure (Mocha/Chai/mock blockchain), not auth - no real auth-providing issue exists in this repo, and the codebase had no authentication at all. This is a small, self- contained foundation just sufficient to make EquipChain#11's own verification steps work (401 without a token, 403 with a non-admin token). It is not a full auth system - no login/register/refresh endpoints. - src/middleware/requireAdmin.js: checks req.user.roles for "admin", per the issue's own spec. - src/middleware/validate.js + src/schemas/admin.schema.js: Zod request validation. Issue EquipChain#8's broader validation work has not landed separately, so schemas are scoped here to what the admin routes need. - src/data/adminStore.js: in-memory storage for users/devices/config + a config audit log (admin identity + timestamp per change), per the issue's own allowance ("initially using in-memory storage, ready for database integration"). Issue EquipChain#22's repository pattern has not landed; this is structured so swapping it out later doesn't change the route handlers' public shape. - src/lib/pagination.js: minimal pagination helper for list endpoints, since issue EquipChain#17's pagination work has not landed either. - src/routes/admin/{users,config,devices,system}.js + index.js: the full endpoint set from the issue - user CRUD, config get/update/ reset, device registration/list/update/remove, and system health/ stats/ws-connections (ws-connections reports a real zero rather than fabricated data, since no WebSocket server exists in this codebase yet). All routes carry @openapi JSDoc annotations, compatible with the swagger documentation work in the other open PR. - index.js: mounts /api/admin with authenticate + requireAdmin, adds express.json() (needed for the new POST/PATCH bodies, wasn't present before). - test/admin.test.js: 18 tests (node:test, matching this repo's actual test convention rather than the issue's suggested Mocha, which isn't configured here) covering the issue's verification steps - 401/403 auth guards, full CRUD for users and devices, config update + audit log + reset, and all three system endpoints. Verified locally: npm test passes 18/18, no regressions on the existing test.
Member
|
Failed CI. Fix it |
Member
|
Can't merge with unresolved conflict and failed CI test. Try and fix it. |
Contributor
Author
|
I will resolve it soon |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #11
Summary
Implements the full admin API surface from the issue: user management,
protocol configuration, device management, and system monitoring, all
restricted to admin-role JWT holders.
Important: a dependency in the issue text is stale
The issue says these endpoints depend on auth middleware from "Issue
#5" — but #5 is actually about testing infrastructure (Mocha/Chai/
Supertest/mock blockchain), not auth. There's no real auth-providing
issue in this repo, and the codebase had zero authentication before
this PR.
Rather than block on a non-existent prerequisite, I built a small,
self-contained
authenticatemiddleware (JWT verification only) —just enough to satisfy #11's own verification steps (401 without a
token, 403 with a non-admin token). This is explicitly not a full
auth system — no login/register/refresh/password endpoints, no
persistent user credentials. It should be superseded by real
session/auth work whenever that lands; happy to adjust if a maintainer
points me to the actual auth issue I should have built against.
What changed
src/middleware/auth.js:authenticate— verifies a Bearer JWT(
JWT_SECRETenv var), setsreq.userfrom the payload.src/middleware/requireAdmin.js: checksreq.user.rolesincludes
admin, per the issue's spec.src/middleware/validate.js+src/schemas/admin.schema.js:Zod request validation. Issue [Security] Implement Input Validation with Zod Schemas and Request Sanitization #8's broader validation work hasn't
landed separately, so schemas are scoped here to what these routes
need.
src/data/adminStore.js: in-memory storage for users, devices,and config (+ an audit log recording admin identity and timestamp
per config change), per the issue's own allowance ("initially using
in-memory storage, ready for database integration"). Structured so
swapping in a real repository layer (issue [Refactor] Implement Repository Pattern for Clean Data Access Layer Abstraction #22, not yet landed)
won't change the route handlers' public shape.
src/lib/pagination.js: minimal pagination helper, since issue[Feature] Create Pagination, Filtering, and Search Utilities for All List Endpoints #17's pagination work hasn't landed either.
src/routes/admin/{users,config,devices,system}.js+index.js: the full endpoint set —GET /,GET /:id,POST /,PATCH /:id,DELETE /:idGET /,PATCH /,POST /resetPOST /,GET /,PATCH /:id,DELETE /:idGET /health,GET /stats,GET /ws-connections(reports a real
count: 0rather than fabricated data, since noWebSocket server exists in this codebase yet)
@openapiJSDoc annotations, compatible with theswagger documentation work in the other open PR (#[swagger PR
number]).
index.js: mounts/api/adminbehindauthenticate+requireAdmin; addedexpress.json()(wasn't present before, isneeded for the new POST/PATCH bodies).
test/admin.test.js: 18 tests usingnode:test(this repo'sactual test convention — the issue suggests Mocha, but that isn't
configured here) covering the issue's verification steps: 401/403
auth guards, full user and device CRUD, config update + audit log +
reset, and all three system endpoints.
Testing
This repo has no external service dependency, so I ran everything
locally:
npm testpasses 18/18, with no regressions on the existingtest.