const Review = require('..
/models/review');
const Campground = require('../models/campground');
module.exports.newReview = async (req, res) => {
const { id } = req.params;
const campground = await Campground.findById(id);
const review = new Review(req.body.review);
review.owner = req.user._id;
campground.reviews.push(review);
await review.save();
await campground.save();
// console.log(campground);
req.flash('success', 'Review successfuly created!');
res.redirect(`/campgrounds/${id}`);
};
module.exports.deleteReview = async (req, res) => {
const { id, review_id } = req.params;
await Campground.findByIdAndUpdate(id, {
$pull: { reviews: review_id }
});
await Review.findByIdAndDelete(review_id);
req.flash('success', 'Review successfuly deleted!');
res.redirect(`/campgrounds/${id}`);
};