<commit_before>/*jslint unparam: true, node: true, plusplus: true, nomen: true, indent: 2, todo: true */
'use strict';

var BookingModel  = require('../models/booking');
var UserModel     = require('../models/user');


var UserController = {

  /**
   * Temp helper /
   * @†odo Remove
   */
  drop: function (req, res, next) {
    UserModel.remove({}, function (err, users) {
      res.redirect('/');
    });
  },


  /**
   * Lists all users
   * @todo  Pagination?
   */
  listAll: function (req, res, next) {

    UserModel.find({}).limit(200).exec(function (err, users) {
      res.render('users/list', {
        title: 'Users',
        users : users
      });
    });
  },


  /**
   * Fetches details and bookings for a single user
   */
  list: function (req, res, next) {
    UserModel.findById(req.params.id, function (err, user) {
      if (err) { return next(err); }

      BookingModel
        .find({ user: user._id })
        .sort({ status: -1})
        .populate('user')
        .populate('gadget', { image: 0 })
        .populate('handoutuser')
        .populate('closeuser')
        .exec(function (err, bookings) {
          if (err) { return next(err); }

          res.render('users/detail', {
            title: user.email,
            euser: user,
            bookings: bookings,
            roles: UserModel.schema.path('role').enumValues
          });

        });
    });
  },

<commit_msg>fixes #25<commit_after>/*jslint unparam: true, node: true, plusplus: true, nomen: true, indent: 2, todo: true */
'use strict';

var BookingModel  = require('../models/booking');
var UserModel     = require('../models/user');


var UserController = {

  /**
   * Temp helper /
   * @†odo Remove
   */
  drop: function (req, res, next) {
    UserModel.remove({}, function (err, users) {
      res.redirect('/');
    });
  },


  /**
   * Lists all users
   * @todo  Pagination?
   */
  listAll: function (req, res, next) {

    UserModel.find({}).limit(200).exec(function (err, users) {
      res.render('users/list', {
        title: 'Users',
        users : users
      });
    });
  },


  /**
   * Fetches details and bookings for a single user
   */
  list: function (req, res, next) {
    UserModel.findById(req.params.id, function (err, user) {
      if (err) { return next(err); }

      BookingModel
        .find({ user: user._id })
        .sort({ status: -1})
        .populate('user')
        .populate('gadget', { image: 0 })
        .populate('handoutuser')
        .populate('closeuser')
        .exec(function (err, bookings) {
          if (err) { return next(err); }

          res.render('users/detail', {
            title: user.displayname,
            euser: user,
            bookings: bookings,
            roles: UserModel.schema.path('role').enumValues
          });

        });
    });
  },


{'fraction_non_alphanumeric': 0.17031029619181948, 'fraction_numerical': 0.004936530324400564, 'mean_word_length': 2.0505376344086024, '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': '7108670', 'n_tokens_mistral': 942, 'n_tokens_neox': 915, 'n_words': 211}