Advertisement
Guest User

Untitled

a guest
Feb 10th, 2017
194
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var RoomSchema = new Schema({
  2.     _creator: {type: mongoose.Schema.Types.ObjectId, ref: 'User'},
  3.     name: { type: String, required: true},
  4.     pass: { type: String, required: true}
  5. });
  6.  
  7. // Scheme for the users of the mongodb
  8. var UserSchema = new Schema({
  9.     email: { type: String, required: true },
  10.     password: { type: String, required: true},
  11.     username: { type: String, required: false },
  12.     appRooms: [ { type: Schema.Types.ObjectId, ref: 'Room' } ]
  13. });
  14.  
  15. UserSchema.set('collection', 'users');
  16. RoomSchema.set('collection', 'rooms');
  17.  
  18. UserSchema.methods.comparePassword = function(candidatePassword, cb) {
  19.     bcrypt.compare(candidatePassword, this.password, function(err, isMatch) {
  20.         if (err) return cb(err);
  21.         cb(null, isMatch);
  22.     });
  23. };
  24.  
  25. exports.User = mongoose.model('User', UserSchema);
  26. exports.Room = mongoose.model('Room', RoomSchema);
  27. exports.mongourl = mongourl;
  28. exports.mongoose = mongoose
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement