From eb045d4b51a4a9ee41059c6920309db3a4191eda Mon Sep 17 00:00:00 2001 From: meet Date: Thu, 8 Aug 2024 20:40:05 +0530 Subject: [PATCH] Added delete users feedback feature for admin --- admin/src/pages/UsersFeedbacks.tsx | 27 +++++++++++++++++++++++--- backend/src/routes/admin/controller.ts | 15 ++++++++++++++ backend/src/routes/admin/route.ts | 4 +++- 3 files changed, 42 insertions(+), 4 deletions(-) diff --git a/admin/src/pages/UsersFeedbacks.tsx b/admin/src/pages/UsersFeedbacks.tsx index 5811e17..5d3c8f2 100644 --- a/admin/src/pages/UsersFeedbacks.tsx +++ b/admin/src/pages/UsersFeedbacks.tsx @@ -54,6 +54,21 @@ const GetFeedbacks = () => { } }; + const handleDeleteFeedback = async (feedbackId: string) => { + try { + await axios.delete(`/api/v1/admin/deletefeedback/${feedbackId}`, { + headers: { + Authorization: `Bearer ${token}`, + }, + }); + toast.success("Feedback deleted successfully"); + setFeedbacks(feedbacks.filter(feedback => feedback.id !== feedbackId)); + } catch (error) { + console.error("Error deleting feedback:", error); + toast.error("Error deleting feedback"); + } + }; + return (
@@ -95,12 +110,18 @@ const GetFeedbacks = () => { {feedback.comment} {feedback.rating} {new Date(feedback.createdAt).toLocaleDateString()} - - + diff --git a/backend/src/routes/admin/controller.ts b/backend/src/routes/admin/controller.ts index d4bfdbc..18bddf3 100644 --- a/backend/src/routes/admin/controller.ts +++ b/backend/src/routes/admin/controller.ts @@ -1088,4 +1088,19 @@ export const downloadFavoritesReportController = async (req: Request, res: Respo error: "An unexpected exception occurred!", }); } +}; + +export const deleteFeedback = async (req: Request, res: Response) => { + const { id } = req.params; + + try { + const feedback = await prisma.feedback.delete({ + where: { id }, + }); + + res.status(200).json({ message: 'Feedback deleted successfully', feedback }); + } catch (error) { + console.error('Error deleting feedback:', error); + res.status(500).json({ error: 'An unexpected error occurred!' }); + } }; \ No newline at end of file diff --git a/backend/src/routes/admin/route.ts b/backend/src/routes/admin/route.ts index 2483c73..d49966f 100644 --- a/backend/src/routes/admin/route.ts +++ b/backend/src/routes/admin/route.ts @@ -1,5 +1,5 @@ import {Router} from 'express'; -import { getPostReactionsController,getFavoritesController,adminLoginController, adminProfileController, allUserForAdmin, blockUserController, unblockUserController, getAdminPostsController, getAdminTrendingPostsController, getAdminStatsController, getGraphsStatsController, updatePostController, deletePostController, getPostByIdController, getAllContactMessages, deleteCommentController, downloadReportController, getFeedbacks, toggleFeedbackVisibility, downloadCommentsReportController, downloadFavoritesReportController, downloadReactionsReportController, downloadUsersReportController, downloadContactMessagesReportController, downloadPostsReportController } from './controller'; +import { getPostReactionsController,getFavoritesController,adminLoginController, adminProfileController, allUserForAdmin, blockUserController, unblockUserController, getAdminPostsController, getAdminTrendingPostsController, getAdminStatsController, getGraphsStatsController, updatePostController, deletePostController, getPostByIdController, getAllContactMessages, deleteCommentController, downloadReportController, getFeedbacks, toggleFeedbackVisibility, downloadCommentsReportController, downloadFavoritesReportController, downloadReactionsReportController, downloadUsersReportController, downloadContactMessagesReportController, downloadPostsReportController, deleteFeedback } from './controller'; import { isAdmin } from '../../middleware/adminAuth'; const adminRouter = Router(); @@ -54,4 +54,6 @@ adminRouter.get("/downloadusersfavoritesreport", downloadFavoritesReportControll adminRouter.get("/downloadusersreactionreport", downloadReactionsReportController); +adminRouter.delete('/deletefeedback/:id', isAdmin, deleteFeedback); + export default adminRouter; \ No newline at end of file