text: var mongoose = require("mongoose");
  const bcrypt = require("bcrypt");
  
  var UserSchema = new mongoose.Schema({
    email: {
      type: String,
      unique: true,
      required: true,
      trim: true
    },
    password: {
      type: String,
      required: true
    },
    timestamp: {
      type: Date,
      default: Date.now
    },
    type: {
      type: String,
      required: true,
      enum: ["ADMIN", "USER", "DOCTOR", "NURSE"],
      default: "USER"
    }
  });
  
  UserSchema.statics.authenticate = (email, password, callback) => {
    User.findOne({ email: email }).exec((err, user) => {
      if (err) {
        console.log("Error in auth");
        return callback(err);
      } else if (!user) {
        var err = new Error("User not found");
        err.status = 401;
        return callback(err);
      }
      bcrypt.compare(password, user.password, (err, result) => {
        if (result === true) {
          return callback(null, user);
        } else {
          return callback();
        }
      });
    });
  };
  
  UserSchema.pre("save", function(next) {
    var user = this;
    bcrypt.hash(user.password, 10, (err, hash) => {
      if (err) {
        return next(err);
      }
      user.password = hash;
      next();
    });
  });
  
  var User = mongoose.model("User", UserSchema);
  module.exports = User;
  