Skip to content

feat: implement product deletion and invalidate dashboard stats query#260

Open
Nareshkumawat-star wants to merge 5 commits into
aditiraj2006:mainfrom
Nareshkumawat-star:fix-dashboard-stats-bug
Open

feat: implement product deletion and invalidate dashboard stats query#260
Nareshkumawat-star wants to merge 5 commits into
aditiraj2006:mainfrom
Nareshkumawat-star:fix-dashboard-stats-bug

Conversation

@Nareshkumawat-star
Copy link
Copy Markdown
Contributor

📌 Linked Issue

Closes #240

📝 Summary of Changes

  • Implemented deleteProduct in MongoStorage to clear products and all their dependencies (comments, reviews, owners, events, transfers, scans, notifications) in MongoDB.
  • Created the secure DELETE /api/products/:id API route protecting it so that only the product owner or an admin user can delete the product.
  • Implemented useDeleteProduct mutation hook in frontend to invalidate the ["/api/stats"] and ["/api/products"] query cache upon success.
  • Updated StatsOverview to show the system-wide stats (including the "Total Products" stat card) for admin users instead of user-specific cards.
  • Added a styled, destructive Delete button with a confirmation dialog on registered-products.tsx for owners and admins, and allowed admins to view all registered products.
  • Updated setup.ts and wrote integration tests in rbac.test.ts to verify product deletion security rules for all user roles.

🔧 Type of Change

  • 🐛 Bug fix
  • ✨ New feature / enhancement
  • 🧹 Refactor / code cleanup
  • 📄 Documentation update
  • 🧪 Test addition or update
  • ⚙️ Configuration / tooling change

🧪 Testing Steps

  1. Run the backend integration test suite locally to verify authentication and RBAC for product deletion:
    npm run test

Log in as an admin or farmer, note the stats on the dashboard, navigate to the registered products page, delete a product, and return to verify that the "Total Products" stat card updates instantly without a manual page refresh.
Environment tested on:

OS: Windows
Node version: v24.11.0
🎥 Demo
✅ Checklist
My code follows the project's coding style and conventions
I have tested my changes locally (npm install + npm run dev)
I have linked the relevant issue above
I have not introduced any new linting errors or warnings
I have updated documentation if needed
My branch is up to date with main
🌟 GSSoC Declaration
This PR is submitted under GSSoC 2026
I have read and followed the

Contributing Guidelines
I have not plagiarised any content
This is my original work

@github-actions github-actions Bot added the gssoc'26 Contribution for GirlScript Summer of Code 2026 label Jun 6, 2026
@aditiraj2006
Copy link
Copy Markdown
Owner

📌 Linked Issue

Closes #240

📝 Summary of Changes

  • Implemented deleteProduct in MongoStorage to clear products and all their dependencies (comments, reviews, owners, events, transfers, scans, notifications) in MongoDB.
  • Created the secure DELETE /api/products/:id API route protecting it so that only the product owner or an admin user can delete the product.
  • Implemented useDeleteProduct mutation hook in frontend to invalidate the ["/api/stats"] and ["/api/products"] query cache upon success.
  • Updated StatsOverview to show the system-wide stats (including the "Total Products" stat card) for admin users instead of user-specific cards.
  • Added a styled, destructive Delete button with a confirmation dialog on registered-products.tsx for owners and admins, and allowed admins to view all registered products.
  • Updated setup.ts and wrote integration tests in rbac.test.ts to verify product deletion security rules for all user roles.

🔧 Type of Change

  • 🐛 Bug fix
  • ✨ New feature / enhancement
  • 🧹 Refactor / code cleanup
  • 📄 Documentation update
  • 🧪 Test addition or update
  • ⚙️ Configuration / tooling change

🧪 Testing Steps

  1. Run the backend integration test suite locally to verify authentication and RBAC for product deletion:
    npm run test

Log in as an admin or farmer, note the stats on the dashboard, navigate to the registered products page, delete a product, and return to verify that the "Total Products" stat card updates instantly without a manual page refresh. Environment tested on:

OS: Windows Node version: v24.11.0 🎥 Demo ✅ Checklist My code follows the project's coding style and conventions I have tested my changes locally (npm install + npm run dev) I have linked the relevant issue above I have not introduced any new linting errors or warnings I have updated documentation if needed My branch is up to date with main 🌟 GSSoC Declaration This PR is submitted under GSSoC 2026 I have read and followed the

Contributing Guidelines I have not plagiarised any content This is my original work

u have conflicts resolve them and also how can u assign a user mail as an admin also add instruction for this also and if possible add screen recording of your work

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

gssoc'26 Contribution for GirlScript Summer of Code 2026

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] Admin dashboard total product count does not update after a product is deleted

2 participants