var mongoose = require('mongoose');
var Schema = mongoose.Schema;
var error = require('../lib/error');

var BookCopyModelSchema = new Schema({
  date: { type: Date, default: Date.now, index: true },
  status: { type: String, default: 'available', required: true, index: true },
  user: { type: Schema.Types.ObjectId, ref: 'UserModel' },
},{
  toObject:  { virtuals: true },
  toJSON:    { virtuals: true }
});

BookCopyModelSchema.virtual('bookCopyId').get(function(){
  return this.id;
});

BookCopyModelSchema.pre('save', function (next) {
  if ('invalid' == this.name) return next(new error.HttpResponseError('Invalid Book Copy'));
  next();
});


module.exports = mongoose.model('BookCopyModel', BookCopyModelSchema);
var mongoose = require('mongoose');
var Schema = mongoose.Schema;
var error = require('../lib/error');

var BookCopyModelSchema = new Schema({
  date: { type: Date, default: Date.now, index: true },
  status: { type: String, default: 'available', required: true, index: true },
  rents: [{ type: Schema.Types.ObjectId, ref: 'RentModel' }]
},{
  toObject:  { virtuals: true },
  toJSON:    { virtuals: true }
});

BookCopyModelSchema.virtual('bookCopyId').get(function(){
  return this.id;
});

BookCopyModelSchema.pre('save', function (next) {
  next();
});


module.exports = mongoose.model('BookCopyModel', BookCopyModelSchema);
change BookCopy Schema