'use strict';

import mongoose from 'mongoose-fill';   // mongoose-fill monkey-patches mongoose.

let Project = require('../project/project.model');

var GroupProjectSchema = new mongoose.Schema({
  name: { type: String, required: true },
  cohort: { type: mongoose.Schema.Types.ObjectId, ref: 'Cohort' },
  project: { type: Project.schema, required: true },
  team: [ { type: mongoose.Schema.Types.ObjectId, ref: 'User' } ]
}, {
  toObject: {
    virtuals: true
  },
  toJSON: {
    virtuals: true
  }
});

module.exports = mongoose.model('GroupProject', GroupProjectSchema);
'use strict';

import mongoose from 'mongoose-fill';

const ObjectId = mongoose.Schema.Types.ObjectId;

const UserSchema = new mongoose.Schema({
  name: {
    type: String,
    required: true,
  },
  email: {
    type: String,
    required: false,
    index: true,
  },
  password: {
    type: String,
    required: true,
  },
}, {
  timestamps: {
    createdAt: 'createdAt',
    updatedAt: 'updatedAt',
  },
});

export default mongoose.model('User', UserSchema);
'use strict';

import mongoose from 'mongoose-fill';   // mongoose-fill monkey-patches mongoose.

var HomeworkSchema = new mongoose.Schema({
  title: String,
  info: String,
  url: String,
  cohort : { type: mongoose.Schema.Types.ObjectId, ref: 'Cohort' },
  assignedOnDate : { type : Date },
  dueDate : { type : Date }
});

(function() {
  /**
   * Autopopulate hook
   */
  var autoPopulate = function(next) {
    this.populate('cohort');
    next();
  };

  HomeworkSchema.
  pre('findOne', autoPopulate).
  pre('find'   , autoPopulate);
})();

module.exports = mongoose.model('Homework', HomeworkSchema);
'use strict';

import mongoose from 'mongoose-fill';   // mongoose-fill monkey-patches mongoose.

var ProjectRequirementSchema = new mongoose.Schema({
  num: Number,
  title: String,
  info: String,
  score: Number,
  comments: String
});

var ProjectRequirement = mongoose.model('ProjectRequirement', ProjectRequirementSchema);

var ProjectSchema = new mongoose.Schema({
  num: Number,
  title: String,
  info: String,
  githubUrl: String,
  deploymentUrl: String,
  comments: String,
  requirements: [ ProjectRequirement.schema ]
});

// Add a preSave hook to ensure default values for the project requirements
ProjectSchema.pre("save", function(next) {
  if ( !this.requirements || this.requirements.length === 0 ) {
    this.requirements = [];
    this.requirements.push({
      num: 1,
      title: 'Project Workflow',
'use strict';

import mongoose from 'mongoose-fill';   // mongoose-fill monkey-patches mongoose.

let AttendanceSchema = new mongoose.Schema({
  date: Date,
  value: String
});

module.exports = mongoose.model('Attendance', AttendanceSchema);
     * @param {Function} callback
     * @return {String}
     * @api public
     */
    encryptPassword(password, callback) {
      if (!password || !this.salt) {
        return null;
      }

      let defaultIterations = 10000;
      let defaultKeyLength = 64;
      let salt = new Buffer(this.salt, 'base64');

      if (!callback) {
        return crypto.pbkdf2Sync(password, salt, defaultIterations, defaultKeyLength)
                     .toString('base64');
      }

      return crypto.pbkdf2(password, salt, defaultIterations, defaultKeyLength, (err, key) => {
        if (err) {
          callback(err);
        } else {
          callback(null, key.toString('base64'));
        }
      });
    }
  };
})();

module.exports = mongoose.model('User', UserSchema);