<commit_before>var Activity = require('../config/models/activity').activity
var Edition  = require('../config/models/activity').edition
var mongoose = require('mongoose')


exports.index = function(req, res) {
  Activity.find().exec(gotActivities)

  function gotActivities(err, all) {
      res.render('activities', {
        'activities': all
      })
  }
}

exports.one = function(req, res) {
  activityId = mongoose.Types.ObjectId.fromString(req.params.activity)
  Activity.findOne({'_id': activityId}).exec(gotActivity)

  function gotActivity(err, one) {
      res.render('activity', {
        'activity': one
      })
  }
}

exports.add = function(req, res) {
  var new_activity = {
    'name'        : req.body.name,
    'description' : req.body.description
  }

  new Activity(new_activity).save()
  res.redirect('/activities')
}

exports.add_edition = function(req, res) {
  start = req.body.start_date
  end = req.body.end_date
  var new_edition = {
    'name'        : req.body.name,
    'start'       : new Date(start.substring(7,11), start.substring(3,5), start.substring(0,2)),
    'end'         : new Date(end.substring(7,11), end.substring(3,5), end.substring(0,2))
  }

  find = {'_id': mongoose.Types.ObjectId.fromString(req.params.activity)}
  update = {$push: {'edition': new Edition(new_edition)}}
  Activity.update(find, update).exec()

  new Edition(new_edition).save()
  res.redirect('/activities/' + req.params.activity)
}<commit_msg>Addressed some comments + minor changes<commit_after>var Activity = require('../config/models/activity').activity
var Edition  = require('../config/models/activity').edition
var mongoose = require('mongoose')
var objId    = mongoose.Types.ObjectId

exports.index = function(req, res) {
  Activity.find().exec(gotActivities)

  function gotActivities(err, all) {
      res.render('activities', {
        'activities': all,
        'user'      : req.session.user
      })
  }
}

exports.one = function(req, res) {
  var activityId = objId.fromString(req.params.activity)
  Activity.findOne({'_id': activityId}).exec(gotActivity)

  function gotActivity(err, one) {
      res.render('activity', {
        'activity'  : one,
        'user'      : req.session.user
      })
  }
}

exports.add = function(req, res) {
  var new_activity = {
    'name'        : req.body.name,
    'description' : req.body.description
  }

  new Activity(new_activity).save()
  res.redirect('/activities')
}

exports.add_edition = function(req, res) {
  var start = req.body.start_date
  var end = req.body.end_date
  var new_edition = {
    'name'        : req.body.name,
    'start'       : new Date(start.substring(7,11), start.substring(3,5), start.substring(0,2)),
    'end'         : new Date(end.substring(7,11), end.substring(3,5), end.substring(0,2))
  }

  var newEdition = new Edition(new_edition)
  newEdition.save(function(err) {
    if(err) {
      res.render('errors', {
        'message': 'Failed to save new edition.',
        'user':   req.user ? req.user.google : false
      });
    }
  })

  var find = {'_id': objId.fromString(req.params.activity)}
  var update = {$push: {'edition': newEdition}}
  Activity.update(find, update).exec()

  res.redirect('/activities/' + req.params.activity)
}
{'fraction_non_alphanumeric': 0.16163793103448276, 'fraction_numerical': 0.008620689655172414, 'mean_word_length': 3.2976190476190474, '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': '3058522', 'n_tokens_mistral': 1091, 'n_tokens_neox': 1084, 'n_words': 188}