<commit_before>'use strict';

/**
 * Module dependencies.
 */
var path = require('path'),
  mongoose = require('mongoose'),
  logger = require(path.resolve('./config/lib/logger')).log4jLog,
  Vote = mongoose.model('Vote'),
  Voteopt = mongoose.model('Voteopt'),
  Poll = mongoose.model('Poll'),
  User = mongoose.model('User'),
  errorHandler = require(path.resolve('./modules/core/server/controllers/errors.server.controller')),
  _ = require('lodash');

/**
 * Create a Vote
 */
exports.create = function (req, res) {
  var vote = new Vote(req.body);
  if (req.user) {
    vote.user = req.user._id;
    vote.guest = false;
  } else {
    vote.ip = getClientIp(req);
    vote.guest = true;
  }
  vote.save().then(vote => {
    console.log(vote);
    res.jsonp(vote);
  }, handleError);
  // let opts = req.body.opts;
  // var promises = [];
  // vote.save()
  //   .then(_vote => {
  //     vote = _vote;
  //     opts.forEach(opt => {
  //       var voteopt = new Voteopt({ opt: opt, vote: _vote._id });
  //       promises.push(voteopt.save());
  //     });
  //     return Promise.all(promises);
  //   }, handleError)
  //   // Resul of save Voteopt
  //   .then(() => {
  //     let pollId = vote.poll._id || vote.poll;
  //     return Poll.countUpVote(pollId);
  //   }, handleError)
  //   .then(() => {
  //     let userId = vote.user._id || vote.user;<commit_msg>Commited from lenh at Sat, Sep 30, 2017  1:10:11 PM<commit_after>'use strict';

/**
 * Module dependencies.
 */
var path = require('path'),
  mongoose = require('mongoose'),
  logger = require(path.resolve('./config/lib/logger')).log4jLog,
  Vote = mongoose.model('Vote'),
  Voteopt = mongoose.model('Voteopt'),
  Poll = mongoose.model('Poll'),
  User = mongoose.model('User'),
  errorHandler = require(path.resolve('./modules/core/server/controllers/errors.server.controller')),
  _ = require('lodash');

/**
 * Create a Vote
 */
exports.create = function (req, res) {
  var vote = new Vote(req.body);
  if (req.user) {
    vote.user = req.user._id;
    vote.guest = false;
  } else {
    vote.ip = getClientIp(req);
    vote.guest = true;
  }
  vote.save().then(_vote => {
    console.log(_vote);
    res.end();
  }, handleError);
  // let opts = req.body.opts;
  // var promises = [];
  // vote.save()
  //   .then(_vote => {
  //     vote = _vote;
  //     opts.forEach(opt => {
  //       var voteopt = new Voteopt({ opt: opt, vote: _vote._id });
  //       promises.push(voteopt.save());
  //     });
  //     return Promise.all(promises);
  //   }, handleError)
  //   // Resul of save Voteopt
  //   .then(() => {
  //     let pollId = vote.poll._id || vote.poll;
  //     return Poll.countUpVote(pollId);
  //   }, handleError)
  //   .then(() => {
  //     let userId = vote.user._id || vote.user;
{'fraction_non_alphanumeric': 0.19784172661870503, 'fraction_numerical': 0.004676258992805755, 'mean_word_length': 2.4719101123595504, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 13, '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': '3400128', 'n_tokens_mistral': 990, 'n_tokens_neox': 990, 'n_words': 182}