<commit_before>var models = require('../models')
  , async = require('async')

exports.addRoutes = function(app, connections) {
  app.post('/v1/comments', function(req, res){
    // TODO: filter body params - known as strong params
    var newComment = res.locals.currentUser.newComment({body: req.body.body})

    newComment.save(function(comment) {
      if (comment) {
        comment.toJSON(function(json) { 
          // TODO: redis publish event instead
          // TODO: measure perf with async.forEach and plain each method
          async.forEach(Object.keys(connections), function(socket, callback) {
            connections[socket].emit('newComment', { comment: json })

            callback(null)
          }, function() {
            res.jsonp(json)
          });
        })
      } else {
        // Just a stupid case - strong parameters will make it cleaner
        res.jsonp({'error': 'incorrect postId'})
      }
    })
  });
}
<commit_msg>Passes postId as a parameter to new comment action.<commit_after>var models = require('../models')
  , async = require('async')

exports.addRoutes = function(app, connections) {
  app.post('/v1/comments', function(req, res){
    // TODO: filter body params - known as strong params
    var newComment = res.locals.currentUser.newComment({
      body: req.body.body,
      postId: req.body.postId
    })

    newComment.save(function(comment) {
      if (comment) {
        comment.toJSON(function(json) { 
          // TODO: redis publish event instead
          // TODO: measure perf with async.forEach and plain each method
          async.forEach(Object.keys(connections), function(socket, callback) {
            connections[socket].emit('newComment', { comment: json })

            callback(null)
          }, function() {
            res.jsonp(json)
          });
        })
      } else {
        // Just a stupid case - strong parameters will make it cleaner
        res.jsonp({'error': 'incorrect postId'})
      }
    })
  });
}

{'fraction_non_alphanumeric': 0.1295647823911956, 'fraction_numerical': 0.0010005002501250625, 'mean_word_length': 2.3333333333333335, 'pattern_counts': {'":': 0, '<': 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': '1421310', 'n_tokens_mistral': 561, 'n_tokens_neox': 550, 'n_words': 139}