Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var mongoose = require('mongoose');
- var Schema = mongoose.Schema;
- var userSchema = new Schema({
- username: { type: String, required: true, unique: true, index: true },
- password: { type: String, required: true , minlength: 128, maxlength: 128 },
- email: { type: String, required: true, unique: true, index: true },
- profileImage: { type: String },
- company: { type: Schema.Types.ObjectId, ref: 'Company' },
- info: {
- name: { type: String, required: true },
- dateOfBirth: { type: Date },
- gender: { type: String, enum: ['M', 'F'] }
- },
- address: [{
- type: Schema.Types.ObjectId, ref: 'Address'
- }],
- contacts: [{
- type: Schema.Types.ObjectId, ref: 'Contact'
- }],
- flags: {
- active: { type: Boolean, required: true },
- deleted: { type: Boolean },
- blocked: { type: Boolean },
- newPassword: { type: Boolean }
- },
- login: {
- lastDate: { type: Date },
- lastIp: { type: String }
- },
- dtCreate: { type: Date },
- dtUpdate: { type: Date }
- });
- userSchema.statics.findComplete = function(findQuery, populateObject) {
- if (typeof populateObject === 'undefined') populateObject = 'company';
- return this.model('User').find(findQuery).populate(populate).exec();
- };
- userSchema.methods.processLogin = function() {
- //Some logic
- return true;
- }
- // userSchema.pre('save', function(next) {
- // var _address = this.parent.dependencies.address;
- // var _contacts = this.parend.dependencies.contacts;
- // console.log(_address);
- // var _address = new Models.Address(req.body.address[item]);
- // _address.save(function(err) {
- // if (err) { res.send({status: 500, message: 'Error while saving address'}); return; }
- // _user.address.push(_address);
- // });
- // next();
- // });
- module.exports = mongoose.model('User', userSchema);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement