From 9dc869552e2948c0e90b75e9feab6d7e77aa5cfb Mon Sep 17 00:00:00 2001 From: Advay Anand Date: Thu, 2 Mar 2023 23:40:22 -0800 Subject: [PATCH 1/2] add reviews page and show users reviews --- api/src/controllers/reviews.ts | 14 ++++- site/src/App.tsx | 2 + site/src/component/SideBar/SideBar.tsx | 12 +++++ .../component/UserReviews/UserReviews.scss | 17 +++++++ .../src/component/UserReviews/UserReviews.tsx | 51 +++++++++++++++++++ site/src/pages/ReviewsPage/ReviewsPage.scss | 0 site/src/pages/ReviewsPage/index.tsx | 41 +++++++++++++++ 7 files changed, 135 insertions(+), 2 deletions(-) create mode 100644 site/src/component/UserReviews/UserReviews.scss create mode 100644 site/src/component/UserReviews/UserReviews.tsx create mode 100644 site/src/pages/ReviewsPage/ReviewsPage.scss create mode 100644 site/src/pages/ReviewsPage/index.tsx diff --git a/api/src/controllers/reviews.ts b/api/src/controllers/reviews.ts index 40e88a2d..84b2599f 100644 --- a/api/src/controllers/reviews.ts +++ b/api/src/controllers/reviews.ts @@ -165,7 +165,17 @@ router.post("/", async function (req, res, next) { * Delete a review */ router.delete('/', async (req, res, next) => { - if (req.session.passport?.admin) { + + const checkUser = async () => { + + let review = await getDocuments(COLLECTION_NAMES.REVIEWS, { + _id: new ObjectID(req.body.id) + }); + + return review.length > 0 && review[0].userID === req.session.passport?.user.id; + } + + if (req.session.passport?.admin || await checkUser()) { console.log(`Deleting review ${req.body.id}`); let status = await deleteDocument(COLLECTION_NAMES.REVIEWS, { @@ -179,7 +189,7 @@ router.delete('/', async (req, res, next) => { res.json(status); } else { - res.json({ error: 'Must be an admin to delete reviews!' }); + res.json({ error: 'Must be an admin or review author to delete reviews!' }); } }) diff --git a/site/src/App.tsx b/site/src/App.tsx index 779ba6a0..a89e88f4 100644 --- a/site/src/App.tsx +++ b/site/src/App.tsx @@ -19,6 +19,7 @@ import ErrorPage from './pages/ErrorPage'; import RoadmapPage from './pages/RoadmapPage'; import ZotisticsPage from './pages/ZotisticsPage'; import AdminPage from './pages/AdminPage'; +import ReviewsPage from './pages/ReviewsPage'; import SideBar from './component/SideBar/SideBar'; import { useAppSelector } from './store/hooks'; @@ -51,6 +52,7 @@ export default function App() { +