fix(admin): mount the /api/admin catalogue and order endpoints the dashboard calls - #1702
Open
MOHITKOURAV01 wants to merge 1 commit into
Open
fix(admin): mount the /api/admin catalogue and order endpoints the dashboard calls#1702MOHITKOURAV01 wants to merge 1 commit into
MOHITKOURAV01 wants to merge 1 commit into
Conversation
…shboard calls frontend/scripts/admin.js was repointed at /api/admin/verify, /api/admin/products and /api/admin/orders in the Admin Dashboard change. None of those paths were mounted. verifyAdminAccess() is the first thing that runs on admin.html, so its 404 read as 'not an admin' and every admin was redirected to signin.html before the page rendered anything. Add adminCatalogController with the four handlers that were missing -- verify, the admin product list, the order queue and the order status transition -- and mount them on adminRoutes, which already applies the auth, admin and rate-limit middleware. These are separate from the public routes on purpose. /api/products restricts itself to PUBLIC_PRODUCT_STATUSES, and an operator managing the catalogue needs to see drafts, inactive and archived rows; /api/orders is scoped to the calling user, and an admin needs the whole queue. Product writes are not reimplemented -- the router delegates create, update and delete to productController, which already owns validation, slugging and archive-on-delete, and differs only in accepting superadmin as well as admin. Status transitions refuse the same moves order.service.js refuses, and the audit row is best-effort: order_status_logs is not in every environment's schema, and losing a log line is worth less than refusing a change the operator has already made.
🔍 Quality Gate Report✅ All quality gates passed!
|
|
Someone is attempting to deploy a commit to the Bhuvansh's projects Team on Vercel. A member of the Team first needs to authorize it. |
🤖 AI Code Review🔴 Score: 50/100 | AI review unavailable at this time. Automated AI review — a human maintainer will also review. |
|
💡 Suggested reviewers based on relevant file history: @Aditya8369, @Pcmhacker-hero |
🟡 PR Health Score: 55/100This PR's health score is below the 75/100 threshold for a healthy label.
Improving these signals will help reviewers engage faster and raise your score. 💪 |
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 #1697
What was wrong
frontend/scripts/admin.jswas repointed at a/api/admin/*surface in the Admin Dashboard change (#1666). None of it was mounted:admin.jscallsadminRoutes.jshadGET /api/admin/verifyGET /api/admin/productsPOST/PUT/DELETE /api/admin/products[/:id]GET /api/admin/ordersPATCH /api/admin/orders/:id/statusverifyAdminAccess()is the first thing that runs onadmin.html. Its 404 maderesponse.successfalsy, which the client reads as "not an admin", so every admin was redirected tosignin.htmlbefore the page rendered anything.What this adds
backend/controllers/adminCatalogController.jswith the four handlers, mounted on the existing admin router — which already appliesadminLimiter,authMiddlewareandadminMiddleware, so they inherit the guard rather than restating it.GET /verify— echoesreq.user. Reaching the handler is itself the answer: the middleware above has already resolved the session and rejected anyone outsideADMIN_ROLES. Kept as its own endpoint so the client has one cheap call before drawing a page it may not be allowed to see.adminMiddlewareacceptssuperadmin, matching the client-side check.GET /products— deliberately not a proxy for/api/products. That route restricts itself toPUBLIC_PRODUCT_STATUSES(constants/productVisibility.js), and an operator managing the catalogue has to see drafts, inactive and archived rows — those are the ones that need attention. Supports?search=,?status=and?includeDeleted=; soft-deleted rows are hidden by default because the dashboard's delete button archives rather than drops, and a list that keeps showing what you just deleted reads as a failed delete.GET /orders— the whole queue rather than/api/orders, which is scoped toreq.user.id. Carriesitem_countoff aLEFT JOINso the dashboard does not make a round trip per row.PATCH /orders/:id/status— whitelisted statuses, and the same transitionsorder.service.js#updateOrderStatusServicerefuses: a cancelled order cannot be moved at all, and a delivered order can only be moved to cancelled (that is a return, and a real thing an operator does). Re-selecting the current status answers 200 without a write, because the<select>fireschangeon re-selection and a 4xx there makes the dropdown bounce back.Product writes are not reimplemented — the router delegates
POST/PUT/DELETEtoproductController, which already owns validation, slug generation and archive-on-delete. The only difference from the public route is the guard:/api/productswrites are gated onROLES.ADMINalone, so a superadmin cannot use them; this router accepts both.Both list responses carry the payload twice — at the top level under
products/orders, which is whatadmin.jsreads, and underdata, which is the shape every other admin route answers with. Cheap, and it avoids a client change landing in the same PR as the server one.Guard
backend/tests/adminCatalogRoutes.test.js, 36 cases. The first block is the one that matters most: it reads the paths out ofadmin.jsand asserts the router answers them, so the endpoints cannot be renamed out from under the dashboard again with every test still green. The rest cover the role gate on each route (admin / superadmin / shopper / anonymous), the response keysadmin.jsactually reads, that the product list carries no public-status filter and the order list nouser_idscope, LIKE-wildcard escaping in the search term, the page-size cap, every allowed status transition and each refused one, and that the status list has not drifted from the copy inorder.service.js.Verification
CI note — merge #1701 first
The Syntax check job fails on this branch, and it is not this change:
frontend/scripts/shop.jsis unparsable onmain— the responsive refactor duplicated and interleaved its initialization block. Every open PR against this repository inherits it, and becausecheck:syntaxis the first CI job and the other two are gated on it, Backend tests and Server boots are skipped rather than run. That is why this PR shows no test result.#1701 fixes it. Once that merges, this branch picks the fix up from
mainwith no rebase needed — the two touch no file in common. All gates pass locally on this branch's changes:and I verified the whole set merges cleanly by merging all five of these branches together locally: no conflicts,
check:syntaxgreen at 659 files, and the full Jest suite at 2976 passing.The
Vercelcheck fails on every PR in this repository with "Authorization required to deploy" against thebhuvanshs-projectsteam, unrelated to any change.