'use strict';

const mongoose = require('mongoose');
const encryptor = require('../utilities/encryptor');

const userSchema = mongoose.Schema({
    username: {
        type: String,
        unique: true
    },
    firstName: String,
    lastName: String,
    salt: String,
    hashedPassword: String
});

userSchema.method({
    authenticate: function (password) {
        let inputHashedPassword = encryptor.generateHashedPassword(this.salt, password);
        return inputHashedPassword === this.hashedPassword;
    }
});

let User;
userSchema.statics.getUser = (user) => {
    return new User({
        username: user.username,
        firstName: user.firstName,
        lastName: user.lastName
    });
};
mongoose.model('User', userSchema);
userSchema = mongoose.model('User');
module.exports = mongoose.model('User');
@@ -44,17 +44,48 @@
 ngoose')
-;
+,%0A    Schema = mongoose.Schema;%0A
 %0Aconst e
@@ -141,32 +141,36 @@
 nst userSchema =
+ new
  mongoose.Schema
@@ -773,26 +773,20 @@
 chema);%0A
-u
+U
 ser
-Schema
  = mongo

fix bug in user model