Advertisement
Guest User

Untitled

a guest
Oct 1st, 2016
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var mongoose     = require('mongoose');
  2. var Schema       = mongoose.Schema;
  3.  
  4. var userSchema   = new Schema({
  5.     username: { type: String, required: true, unique: true, index: true },
  6.     password: { type: String, required: true , minlength: 128, maxlength: 128 },
  7.     email: { type: String, required: true, unique: true, index: true },
  8.     profileImage: { type: String },
  9.     company: { type: Schema.Types.ObjectId, ref: 'Company' },
  10.     info: {
  11.         name: { type: String, required: true },
  12.         dateOfBirth: { type: Date },
  13.         gender: { type: String, enum: ['M', 'F'] }
  14.     },
  15.     address: [{
  16.         type: Schema.Types.ObjectId, ref: 'Address'
  17.     }],
  18.     contacts: [{
  19.         type: Schema.Types.ObjectId, ref: 'Contact'
  20.     }],
  21.     flags: {
  22.         active: { type: Boolean, required: true },
  23.         deleted: { type: Boolean },
  24.         blocked: { type: Boolean },
  25.         newPassword: { type: Boolean }
  26.     },
  27.     login: {
  28.         lastDate: { type: Date },
  29.         lastIp: { type: String }
  30.     },
  31.     dtCreate: { type: Date },  
  32.     dtUpdate: { type: Date }
  33. });
  34.  
  35. userSchema.statics.findComplete = function(findQuery, populateObject) {
  36.     if (typeof populateObject === 'undefined') populateObject = 'company';
  37.  
  38.     return this.model('User').find(findQuery).populate(populate).exec();
  39. };
  40.  
  41. userSchema.methods.processLogin = function() {
  42.     //Some logic
  43.  
  44.     return true;
  45. }
  46.  
  47. // userSchema.pre('save', function(next) {
  48. //  var _address    = this.parent.dependencies.address;
  49. //  var _contacts   = this.parend.dependencies.contacts;
  50.  
  51. //  console.log(_address);
  52.    
  53. //  var _address = new Models.Address(req.body.address[item]);
  54. //  _address.save(function(err) {
  55. //      if (err) { res.send({status: 500, message: 'Error while saving address'}); return; }
  56. //      _user.address.push(_address);
  57. //  });
  58.    
  59. //  next();
  60. // });
  61.  
  62. module.exports = mongoose.model('User', userSchema);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement