Skip to content

Commit

Permalink
fix: takes passport's user name instead of the one passed in frontend
Browse files Browse the repository at this point in the history
  • Loading branch information
timobraz committed Jan 23, 2024
1 parent 2b697d8 commit 68f5ca6
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion api/src/controllers/reviews.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,6 @@ router.get('/', async function (req, res, next) {
router.post('/', async function (req, res, next) {
if (req.session.passport) {
//^ this should be a middleware check smh
console.log('Adding Review:', req.body);

// check if user is trusted
const reviewsCollection = await getCollection(COLLECTION_NAMES.REVIEWS);
Expand Down Expand Up @@ -165,6 +164,9 @@ router.post('/', async function (req, res, next) {
if (reviews?.length > 0)
return res.status(400).json({ error: 'Review already exists for this professor and course!' });
// add review to mongo
req.body.userDisplay =
req.body.userDisplay === 'Anonymous Peter' ? 'Anonymous Peter' : req.session.passport.user.name;
req.body.userID = req.session.passport.user.id;
await addDocument(COLLECTION_NAMES.REVIEWS, req.body);

// echo back body
Expand Down

0 comments on commit 68f5ca6

Please sign in to comment.