title: I get an error when tried to make a comment ( or a review ) I have no clear idea if what the issue is
body: <p>I am trying to create a small webapp just to learn more. Well the app is to share contact information for penpals. I already made registering, creating accounts, image upload, login and logout. Right now what I am struggling with is, commenting part. After someone created an account and is logged in they can post comments on other people's profile page. So here's the issue when I tried to post the comment, it will show me this error.</p>
  <pre><code>
  &quot;review&quot; is required
  
  Error: &quot;review&quot; is required at module.exports.validateReview (/app/middleware.js:49:8) at 
  Layer.handle [as handle_request] (/app/node_modules/express/lib/router/layer.js:95:5) at next 
  (/app/node_modules/express/lib/router/route.js:137:13) at module.exports.isLoggedIn 
  (/app/middleware.js:12:5) at Layer.handle [as handle_request] (/app/node_modules/express/lib/router
  /layer.js:95:5) at next (/app/node_modules/express/lib/router/route.js:137:13) at Route.dispatch 
  (/app/node_modules/express/lib/router/route.js:112:3) at Layer.handle [as handle_request] 
  (/app/node_modules/express/lib/router/layer.js:95:5) at /app/node_modules/express/lib/router
  /index.js:281:22 at Function.process_params (/app/node_modules/express/lib/router/index.js:335:12) at
   next (/app/node_modules/express/lib/router/index.js:275:10) at Function.handle (/app/node_modules/express/lib/router/index.js:174:3) at router (/app/node_modules/express/lib/router/index.js:47:12) 
  at Layer.handle [as handle_request] (/app/node_modules/express/lib/router/layer.js:95:5) at 
  trim_prefix (/app/node_modules/express/lib/router/index.js:317:13) at /app/node_modules/express
  /lib/router/index.js:284:7
  </code></pre>
  <p>This error is generated by this part in my middleware.js</p>
  <pre><code>module.exports.validateReview = (req, res, next) =&gt; {
      const{ error } = reviewSchema.validate(req.body);
      if (error) {
      const msg = error.details.map(el =&gt; el.message).join(',')
      throw new ExpressError(msg, 400)
      }else {
      next();
      }
  }
  
  </code></pre>
  <p>And this is my routes file for reviews (or comments)</p>
  <pre><code>const express = require('express');
  const router = express.Router({ mergeParams: true });
  // const { reviewSchema } = require('../schemas.js');
  const { validateReview, isLoggedIn, isReviewAuthor } = require('../middleware');
  const Penpal = require('../models/penpal');
  const Review = require('../models/review');
  const reviews = require('../controllers/reviews');
  const ExpressError = require('../utils/ExpressError');
  const catchAsync = require('../utils/catchAsync');
  
  router.post('/',isLoggedIn, validateReview, catchAsync(reviews.createReview));
  router.delete('/:reviewId', isLoggedIn, isReviewAuthor, catchAsync(reviews.deleteReview));
  
  module.exports = router;
  </code></pre>
  <p>Here to see if what is wrong I tried to do the same thing by removing this 'validateReview' part from 'router.post' and then the comment (or the review) get created but it doesn't show the body of the review I typed.
  I will post the form I created for this and the controller file too.</p>
  <p>This is the form</p>
  <pre><code>  &lt;div class=&quot;col-6&quot;&gt;
      &lt;% if(currentUser){ %&gt;
      &lt;h2&gt;Write a comment&lt;/h2&gt;
      &lt;form action=&quot;/penpals/&lt;%=penpal._id%&gt;/reviews&quot; method=&quot;POST&quot; class=&quot;mb-3 validated-form&quot; novalidate&gt;
        &lt;div class=&quot;mb-3&quot;&gt;
          &lt;label class=&quot;form-label&quot; for=&quot;body&quot;&gt;Review&lt;/label&gt;
          &lt;textarea class=&quot;form-control&quot; name=&quot;review[body]&quot; id=&quot;body&quot; cols=&quot;30&quot; rows=&quot;3&quot; required&gt;&lt;/textarea&gt;
          &lt;div class=&quot;valid-feedback&quot;&gt;
            Looks good!
          &lt;/div&gt;
        &lt;/div&gt;
        &lt;button class=&quot;btn btn-success&quot;&gt;Submit&lt;/button&gt;
      &lt;/form&gt;
      &lt;% } %&gt;
      &lt;% for(let review of penpal.reviews) { %&gt;
      &lt;div class=&quot;card mb-3&quot;&gt;
        &lt;div class=&quot;card-body&quot;&gt;
      &lt;h5 class=&quot;card-title&quot;&gt;&lt;%= review.author.username %&gt;&lt;/h5&gt;
      &lt;p class=&quot;card-text&quot;&gt;Comment: &lt;%= review.body %&gt;&lt;/p&gt;
      &lt;% if(currentUser &amp;&amp; review.author.equals(currentUser._id)) { %&gt;
      &lt;form action=&quot;/penpals/&lt;%= penpal._id %&gt;/reviews/&lt;%= review._id %&gt;?_method=DELETE&quot; method=&quot;POST&quot;&gt;
        &lt;button class=&quot;btn btn-danger&quot;&gt;Delete&lt;/button&gt;
      &lt;/form&gt;
      &lt;% } %&gt;
        &lt;/div&gt;
      &lt;/div&gt;
      &lt;% } %&gt;
    &lt;/div&gt;
  </code></pre>
  <p>And then here in this form file instead of displaying 'review.body' I tried displaying just 'review' to see if what's in there. And there was everything about the author and all, but the body of the review wasn't there.</p>
  <p>This is how it looked,</p>
  <blockquote>
  <p>Comment: { _id: 60755176afda9d0015b69829, author: { _id: 60716c0c5de17600155f4d1c, email: 'tim@gmail.com', username: 'tim', __v: 0 }, __v: 0 }</p>
  </blockquote>
  <p>I doubt if there's something wrong with my controller files, I will post both controller files for my penpals and reviews.</p>
  <p>This is the reviews one</p>
  <pre><code>const Penpal = require('../models/penpal');
  const Review = require('../models/review');
  
  module.exports.createReview = async (req, res) =&gt; {
      const penpal = await Penpal.findById(req.params.id);
      const review = new Review(req.body.review);
      review.author = req.user._id;
      penpal.reviews.push(review);
      await review.save();
      await penpal.save();
  //    req.flash('success', 'Created a new comment!');
      res.redirect(`/penpals/${penpal._id}`);
  }
  
  module.exports.deleteReview = async(req, res) =&gt; {
      const { id, reviewId } = req.params;
      await Penpal.findByIdAndUpdate(id, { $pull: { reviews: reviewId }});
      await Review.findByIdAndDelete(req.params.reviewId);
      req.flash('success', 'Comment deleted successfully!');
      res.redirect(`/penpals/${ id }`);
  }
  </code></pre>
  <p>This is a part of the penpals controller file that I believe is important for this case,</p>
  <pre><code>module.exports.showPenpal = async (req, res) =&gt; {
      const penpal = await Penpal.findById(req.params.id).populate({
      path: 'reviews',
      populate:{
          path: 'author'
      }
      }).populate('author');
      if(!penpal){
      req.flash('error', &quot;Can't find that penpal!&quot;);
      return res.redirect('/penpals');
      }
      res.render('penpals/show', { penpal })
  }
  </code></pre>
  <p><strong>[edit]This is the review model</strong></p>
  <pre><code>const mongoose = require('mongoose');
  const Schema = mongoose.Schema;
  
  const reviewSchema = new Schema({
      body: String,
      author: {
      type: Schema.Types.ObjectId,
      ref: 'User'
      }
  });
  
  module.exports = mongoose.model(&quot;Review&quot;, reviewSchema);
  </code></pre>
  <p>This is the user model I am referencing in review model.</p>
  <pre><code>const mongoose = require('mongoose');
  const Schema = mongoose.Schema;
  const passportLocalMongoose = require('passport-local-mongoose');
  
  const UserSchema = new Schema({
      email: {
          type: String,
          required: true,
          unique: true
      }
  });
  
  UserSchema.plugin(passportLocalMongoose);
  
  module.exports = mongoose.model('User', UserSchema);
  </code></pre>
  <p>This is the package.json file</p>
  <pre><code>{
    &quot;name&quot;: &quot;cs-50&quot;,
    &quot;version&quot;: &quot;1.0.0&quot;,
    &quot;description&quot;: &quot;&quot;,
    &quot;main&quot;: &quot;index.js&quot;,
    &quot;scripts&quot;: {
      &quot;test&quot;: &quot;echo \&quot;Error: no test specified\&quot; &amp;&amp; exit 1&quot;,
      &quot;start&quot;: &quot;node app.js&quot;
    },
    &quot;keywords&quot;: [],
    &quot;author&quot;: &quot;&quot;,
    &quot;license&quot;: &quot;ISC&quot;,
    &quot;dependencies&quot;: {
      &quot;@mapbox/mapbox-sdk&quot;: &quot;^0.12.1&quot;,
      &quot;bs-custom-file-input&quot;: &quot;^1.3.4&quot;,
      &quot;cloudinary&quot;: &quot;^1.25.1&quot;,
      &quot;connect-flash&quot;: &quot;^0.1.1&quot;,
      &quot;connect-mongo&quot;: &quot;^3.2.0&quot;,
      &quot;dotenv&quot;: &quot;^8.2.0&quot;,
      &quot;ejs&quot;: &quot;^3.1.6&quot;,
      &quot;ejs-mate&quot;: &quot;^3.0.0&quot;,
      &quot;express&quot;: &quot;^4.17.1&quot;,
      &quot;express-mongo-sanitize&quot;: &quot;^2.0.2&quot;,
      &quot;express-session&quot;: &quot;^1.17.1&quot;,
      &quot;flash&quot;: &quot;^1.1.0&quot;,
      &quot;helmet&quot;: &quot;^4.4.1&quot;,
      &quot;install&quot;: &quot;^0.13.0&quot;,
      &quot;joi&quot;: &quot;^17.4.0&quot;,
      &quot;mapbox&quot;: &quot;^1.0.0-beta10&quot;,
      &quot;method-override&quot;: &quot;^3.0.0&quot;,
      &quot;mongoose&quot;: &quot;^5.12.3&quot;,
      &quot;multer&quot;: &quot;^1.4.2&quot;,
      &quot;multer-storage-cloudinary&quot;: &quot;^4.0.0&quot;,
      &quot;passport&quot;: &quot;^0.4.1&quot;,
      &quot;passport-local-mongoose&quot;: &quot;^6.1.0&quot;,
      &quot;sanitize-html&quot;: &quot;^2.3.3&quot;
    }
  }
  </code></pre>
  <p>I literally spent more than four days trying play around. But I still have no idea if what's going wrong. Any kind of help is really appreciated! Thank you for your time.</p>