diff --git a/src/libs/db/mongoose.js b/src/libs/db/mongoose.js index 58d90d44b1022961b8111023d785807fef14a0e9..896438a84da346d4840a8dd86722cadebf050a21 100644 --- a/src/libs/db/mongoose.js +++ b/src/libs/db/mongoose.js @@ -13,7 +13,7 @@ module.exports = () => { log.debug(`Connecting to MongDB on URI ${mongoUri}`); const db = mongoose.connect(mongoUri); - mongoose.connection.once('open', () => { log.info("MongoDB connected"); }); + mongoose.connection.once('open', () => { log.info('MongoDB connected'); }); return db; }; diff --git a/src/libs/models/user.js b/src/libs/models/user.js index 5a86df8e511b2d554674c783335391341be2cbaf..b4648eb12d1e8443df8df5af48ffca7670277797 100644 --- a/src/libs/models/user.js +++ b/src/libs/models/user.js @@ -1,47 +1,48 @@ -var mongoose = require('mongoose'); -var Schema = mongoose.Schema; -var bcrypt = require('bcrypt'); +const mongoose = require('mongoose'); +const bcrypt = require('bcrypt'); +const Schema = mongoose.Schema; + +// set up a mongoose model var UserSchema = new Schema({ - email:{ - type: String, - required: true, - unique: true - }, + email: { + type: String, + unique: true, + required: true + }, password: { - type: String, - required: true - } + type: String, + required: true + } }); -UserSchema.pre('save', function(next){ - var user = this; - if(this.isModified('password') || this.isNew){ - bcrypt.genSalt(128, function (err, salt){ - if(err){ - return next(err); - } - bcrypt.hash(user.password, salt, function(err, hash){ - if(err){ - return next(err); - } - user.password = hash; - next(); - }); - }); - } - else{ - return next(); - } +UserSchema.pre('save', function (next) { + var user = this; + if (this.isModified('password') || this.isNew) { + bcrypt.genSalt(128, function (err, salt) { + if (err) { + return next(err); + } + bcrypt.hash(user.password, salt, function (err, hash) { + if (err) { + return next(err); + } + user.password = hash; + next(); + }); + }); + } else { + return next(); + } }); -UserSchema.methods.comparePassword = function(passw, cb){ - bcrypt.compare(passw, this.password, function(err, isMatch){ - if(err){ - return cb(err); - } - cb(null, isMatch) - }); +UserSchema.methods.comparePassword = function (passw, cb) { + bcrypt.compare(passw, this.password, function (err, isMatch) { + if (err) { + return cb(err); + } + cb(null, isMatch); + }); }; module.exports = mongoose.model('User', UserSchema);