<commit_before>// events.js
var utils = require('../config/utils');

module.exports = {
  getNearbyEvents: function(){
    /* Select all events from events table where distance
       between user and events < some number. */
  },

  createEvent: function(req, res){
    var models = req.app.get('models');
    var Event = models.Event;

    /* The newEvent object contains a number of properties -- some obtained
       from the body of the request and some defaults. This object is used
       to build the Sequelize model that will be saved in the database. */
    var newEvent = {};
    newEvent.HostId = req.body.HostId;
    newEvent.locationId = req.body.locationId;
    newEvent.plannedTime = req.body.plannedTime;
    newEvent.capacity = req.body.capacity;
    newEvent.currentSize = 1;
    newEvent.currentActivity = "Planning";
    newEvent.completedStatus = false;

    /* Builds a Sequelize model based on newEvent object and saves to the database. 
       Sends a response if this is successful. Otherwise, logs an error. */
    Event.sync().then(function () {
      return Event.create(newEvent);
    }).then (function (newEvent) {
      utils.sendResponse(res, 201, newEvent);
    }).catch(function (err) {
      console.log('Error: ', err);
    });
  },

  getEvent: function(){

  },

  updateEvent: function(){

  }
};
<commit_msg>completed getEvent and updateEvent controller functions<commit_after>// events.js
var utils = require('../config/utils');

module.exports = {
  getNearbyEvents: function(){
    /* Select all events from events table where distance
       between user and events < some number. */
  },

  createEvent: function(req, res){
    var models = req.app.get('models');
    var Event = models.Event;

    /* The newEvent object contains a number of properties -- some obtained
       from the body of the request and some defaults. This object is used
       to build the Sequelize model that will be saved in the database. */
    var newEvent = {};
    newEvent.HostId = req.body.HostId;
    newEvent.locationId = req.body.locationId;
    newEvent.plannedTime = req.body.plannedTime;
    newEvent.capacity = req.body.capacity;
    newEvent.currentSize = req.body.currentSize;
    newEvent.currentActivity = req.body.currentActivity;
    newEvent.completedStatus = false;

    /* Builds a Sequelize model based on newEvent object and saves to the database. 
       Sends a response if this is successful. Otherwise, logs an error. */
    Event.sync().then(function () {
      return Event.create(newEvent);
    }).then (function (newEvent) {
      utils.sendResponse(res, 201, newEvent);
    }).catch(function (err) {
      console.log('Error: ', err);
    });
  },

  getEvent: function(req, res){
    var models = req.app.get('models');
    var Event = models.Event;
    var eventId = req.params.eventId;

    Event.sync().then(function () {
      return Event.findById(eventId);
    }).then(function (event) {
      utils.sendResponse(res, 200, event)
    }).catch(function (err) {
      console.log('Error: ', err);
    });
  },

  updateEvent: function (req, res) {
    var models = req.app.get('models');
    var Event = models.Event;
    var eventId = req.params.eventId;

    var updatedEvent = {};
    updatedEvent.HostId = req.body.HostId;
    updatedEvent.locationId = req.body.locationId;
    updatedEvent.plannedTime = req.body.plannedTime;
    updatedEvent.capacity = req.body.capacity;
    updatedEvent.currentSize = req.body.currentSize;
    updatedEvent.currentActivity = req.body.currentActivity;
    updatedEvent.completedStatus = req.body.completedStatus;

    var options = {};
    options.where = { id: eventId };
    options.returning = true;

    Event.sync().then(function () {
      return Event.update(updatedEvent, options);
    }).then(function (update) {
      /* Sequelize update method returns an array. Second element is an 
         array contained updated records. We want the first updated record 
         since there should be only one. See documentation of .update() at: 
         http://docs.sequelizejs.com/en/latest/api/model/#updatevalues-options-promisearrayaffectedcount-affectedrows */
      updatedEvent = update[1][0];
      utils.sendResponse(res, 200, updatedEvent);
    }).catch(function (err) {
      console.log('Error: ', err);
    });
  }
};

{'fraction_non_alphanumeric': 0.11874567673507032, 'fraction_numerical': 0.0034586119437399125, 'mean_word_length': 3.020389249304912, 'pattern_counts': {'":': 0, '<': 5, '<?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': '1853689', 'n_tokens_mistral': 1272, 'n_tokens_neox': 1222, 'n_words': 354}