<commit_before>var keystone = require('keystone');
var io = require('../../sockets/socket');
var moment = require('moment');

exports = module.exports = function(req, res) {

  var Session = keystone.list('Session');

  var view = new keystone.View(req, res);
  var locals = res.locals;

  locals.sessions = [];
  locals.today = new Date().getDay();

  var now = new Date();
  var today = moment().startOf('day').toDate();

  Session.model.find({active: true, course: locals.course._id, startDate: {$lte: now}, endDate: {$gte: today}}).sort(
      {weekday: 'asc', startTime: 'asc'}).exec(function(err, sessions) {

    if (sessions) {
      sessions.forEach(function(session) {
        var sess = session.toJSON();
        sess.id = session._id.toString();
        sess.timespan = session.getTimespan();
        sess.datespan = session.getDatespan();
        sess.weekdayString = session.weekdayString;
        locals.sessions.push(sess);
      });
    }

    if (err) {
      req.flash('error', 'Harjoitusryhmien hakeminen epäonnistui.');
    }

    view.render('sessions', locals);<commit_msg>Show groups starting during the current week<commit_after>var keystone = require('keystone');
var io = require('../../sockets/socket');
var moment = require('moment');

exports = module.exports = function(req, res) {

  var Session = keystone.list('Session');

  var view = new keystone.View(req, res);
  var locals = res.locals;

  locals.sessions = [];
  locals.today = new Date().getDay();

  var now = new Date();
  var today = moment().startOf('day').toDate();
  var endOfWeek = moment().startOf('isoWeek').add(7, 'd').toDate();

  Session.model.find({active: true, course: locals.course._id, startDate: {$lte: endOfWeek}, endDate: {$gte: today}}).sort(
      {weekday: 'asc', startTime: 'asc'}).exec(function(err, sessions) {

    if (sessions) {
      sessions.forEach(function(session) {
        var sess = session.toJSON();
        sess.id = session._id.toString();
        sess.timespan = session.getTimespan();
        sess.datespan = session.getDatespan();
        sess.weekdayString = session.weekdayString;
        locals.sessions.push(sess);
      });
    }

    if (err) {
      req.flash('error', 'Harjoitusryhmien hakeminen epäonnistui.');
    }

    view.render('sessions', locals);
{'fraction_non_alphanumeric': 0.17065737919024815, 'fraction_numerical': 0.00043535045711797995, 'mean_word_length': 3.3938814531548758, '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': '4478382', 'n_tokens_mistral': 760, 'n_tokens_neox': 741, 'n_words': 155}