text: const mongoose = require('mongoose')
  const Schema = mongoose.Schema
  const bcrypt = require('bcryptjs');
  mongoose.promise = Promise
  
  // Define userSchema
  const userSchema = new Schema({
  
      username: { type: String, unique: true, required: true },
      password: { type: String, required: true },
      firstName: { type: String, required: true },
      lastName: { type: String, required: true },
      age: { type: String, required: true},
      email: { type: String },
      phone: { type: String },
      // date1:{type:Date},
      // date2:{type:Date}
      
  })
  
  // Define schema methods
  userSchema.methods = {
      checkPassword: function (inputPassword) {
          return bcrypt.compareSync(inputPassword, this.password)
      },
      hashPassword: plainTextPassword => {
          return bcrypt.hashSync(plainTextPassword, 10)
      }
  }
  
  // Define hooks for pre-saving
  userSchema.pre('save', function (next) {
      if (!this.password) {
          console.log('models/user.js =======NO PASSWORD PROVIDED=======')
          next()
      } else {
          console.log('models/user.js hashPassword in pre save');
  
          this.password = this.hashPassword(this.password)
          next()
      }
  })
  
  const User = mongoose.model('User', userSchema)
  module.exports = User