import mongoose from 'mongoose';
import db from '../db';

const UserSchema = new mongoose.Schema({
  name: {type: String, index: {unique: true}},
  email: String,
  pass: String,
  key: String,
  level: String,
  location: String,
  devices: [String]
});

// changelog query helper
UserSchema.query.log = function <Q extends mongoose.DocumentQuery<any, any>> (req) {
  db.log(req, this);
  return this;
}

export default mongoose.model<any, mongoose.Model<any, any>>('user', UserSchema);