<commit_before>// The Review controller

var mongoose = require('mongoose');
var Review = require('../models/reviewModel.js');
var Business = require('../models/businessModel.js');
var User = require('../models/userModel.js');

  /**
   * Creates a new Review from the data request
   * @param {Object} req HTTP request object.
   * @param {Object} res HTTP response object.
   */
exports.createNewReview = function(req, res) {

    console.log('POST - /review');
    var errors = [];

    var userId = req.body.userId;
    var businessId = req.body.businessId;
    var content = req.body.content;

    // validate the user exists
    var user = User.findOne({ "_id": userId }, function (err, user) {
      if (err) {
        var errorMsg = "Could not add the review. No user found with id: " + userId;
        console.log(errorMsg);
        errors.push(errorMsg);        
      }
    });

    // validate the business exists
    var business = Business.findOne({ "_id": businessId }, function (err, business) {
      if (err) {<commit_msg>added user security when adding business review<commit_after>// The Review controller

var mongoose = require('mongoose');
var Review = require('../models/reviewModel.js');
var Business = require('../models/businessModel.js');
var User = require('../models/userModel.js');

  /**
   * Creates a new Review from the data request
   * @param {Object} req HTTP request object.
   * @param {Object} res HTTP response object.
   */
exports.createNewReview = function(req, res) {

    console.log('POST - /review');
    var errors = [];

    var userId = req.body.userId;
    var businessId = req.body.businessId;
    var content = req.body.content;

    if (req.user.id != userId) {
        res.statusCode = 403;
        return res.send({ error: 'Fake user' });
    }
    
    // validate the user exists
    var user = User.findOne({ "_id": userId }, function (err, user) {
      if (err) {
        var errorMsg = "Could not add the review. No user found with id: " + userId;
        console.log(errorMsg);
        errors.push(errorMsg);        
      }
    });

    // validate the business exists
    var business = Business.findOne({ "_id": businessId }, function (err, business) {
      if (err) {
{'fraction_non_alphanumeric': 0.13857845328565044, 'fraction_numerical': 0.0013410818059901655, 'mean_word_length': 2.686985172981878, 'pattern_counts': {'":': 4, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5605708', 'n_tokens_mistral': 651, 'n_tokens_neox': 650, 'n_words': 206}