<commit_before>/**
 * @fileOverview GET /together page.
 */

var log = require('logg').getLogger('app.ctrl.city.Together');
var ControllerBase = require('nodeon-base').ControllerBase;

var TogetherEnt = require('../../entities/together.ent');


/**
 * The Together events page.
 *
 * @contructor
 * @extends {app.ControllerBase}
 */
var Home = module.exports = ControllerBase.extendSingleton(function(){
  this.use.push(this._fetchEvent.bind(this));
  this.use.push(this._showTogether.bind(this));
});

/**
 * Will check if exists and fetch the Together event record.
 *
 * @param {Object} req The request Object.
 * @param {Object} res The response Object.
 * @param {Function} next Pass control.
 * @private
 */
Home.prototype._fetchEvent = function (req, res, next) {
  TogetherEnt.getInstance().readOne({
    cityOwner: req.city._id,
    upcoming: true,
  })
    .bind(this)
    .then(function(result) {
      if (!result) {
        this.show404();
      } else {
        res.locals.together = result;
        next();
      }
    })
    .catch(function (err) {
      log.warn('_fetchEvent() :: Error on fetching together event:', err);
      if (typeof err.toApi === 'function') {
        err = err.toApi();
      }
      res.status(500).render('city/error/500', {error: err});
    });
};

/**
 * The Together view.
 *
 * @param {Object} req The request Object.
 * @param {Object} res The response Object.
 */
Home.prototype._showTogether = function(req, res) {

  res.render('city/together', {
    og: null, // title, site_name, url, description, image, appId, type<commit_msg>Overwrite OG tags on together page events<commit_after>/**
 * @fileOverview GET /together page.
 */

var log = require('logg').getLogger('app.ctrl.city.Together');
var ControllerBase = require('nodeon-base').ControllerBase;

var TogetherEnt = require('../../entities/together.ent');


/**
 * The Together events page.
 *
 * @contructor
 * @extends {app.ControllerBase}
 */
var Home = module.exports = ControllerBase.extendSingleton(function(){
  this.use.push(this._fetchEvent.bind(this));
  this.use.push(this._populateOgTags.bind(this));
  this.use.push(this._showTogether.bind(this));
});

/**
 * Will check if exists and fetch the Together event record.
 *
 * @param {Object} req The request Object.
 * @param {Object} res The response Object.
 * @param {Function} next Pass control.
 * @private
 */
Home.prototype._fetchEvent = function (req, res, next) {
  TogetherEnt.getInstance().readOne({
    cityOwner: req.city._id,
    upcoming: true,
  })
    .bind(this)
    .then(function(result) {
      if (!result) {
        this.show404();
      } else {
        res.locals.together = result;
        next();
      }
    })
    .catch(function (err) {
      log.warn('_fetchEvent() :: Error on fetching together event:', err);
      if (typeof err.toApi === 'function') {
        err = err.toApi();
      }
      res.status(500).render('city/error/500', {error: err});
    });
};

Home.prototype._populateOgTags = function(req, res, next) {
  if (!res.locals.city || !res.locals.city.og) {
    next();
    return;
  }
  var origUrl = req.city.og.url;
  res.locals.city.og.url += '/together';
  res.locals.city.og.image = 'http://' + origUrl + '/img/we-are-together-logo.png';
  res.locals.city.og.description = res.locals.together.tagline;
  next();
};

/**
 * The Together view.
 *
 * @param {Object} req The request Object.
 * @param {Object} res The response Object.
 */
Home.prototype._showTogether = function(req, res) {

  res.render('city/together', {
    og: null, // title, site_name, url, description, image, appId, type
{'fraction_non_alphanumeric': 0.16763485477178422, 'fraction_numerical': 0.004979253112033195, 'mean_word_length': 3.194895591647332, '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': '6121350', 'n_tokens_mistral': 1187, 'n_tokens_neox': 1163, 'n_words': 267}