arnaucube
arnaucube/socketioMEANseedPublic Self-hosted repository
socketioMEANseed/server/models/userModel.js
server/models/userModel.jsRaw
  1var mongoose = require('mongoose');
  2var mongooseUniqueValidator = require('mongoose-unique-validator');
  3var Schema = mongoose.Schema;
  4var userSchema = new Schema({
  5    name: {type: String, required: true, unique: true},
  6    role: {type: String, required: true},
  7    password: {type: String, select: false},
  8    tokens: [{
  9        userAgent: {type: String},
 10        token: {type: String},
 11        os: {type: String},
 12        browser: {type: String},
 13        device: {type: String},
 14        os_version: {type: String},
 15        browser_version: {type: String},
 16        ip: {type: String},
 17        lastLogin: {type: Date},
 18        birthdate: {type: Date},
 19    }],
 20    testimonial: {type :String},//Para la landing page, sera como una review del sitio
 21    email: {type: String, required: true, unique: true},
 22    description: {type: String},
 23    direction: {type: String},
 24    city: {type: String},
 25    avatar: {type: String},
 26    background: {type: String},
 27    attributes: {
 28        height: {type: Number},
 29        weight: {type: Number},
 30        gender: {type: String},//Home, Dona, Altres -->com a mínim aquestes 3 opcions, més endavant tenim el debat de com s'enfoca
 31        age: {type: Number}
 32    },
 33    publications: [{
 34        type: mongoose.Schema.Types.ObjectId,
 35        ref: 'publicationModel'
 36    }],
 37    runs: [{
 38        type: mongoose.Schema.Types.ObjectId,
 39        ref: 'runModel'
 40    }],
 41    totalkm: {type: Number},
 42    conversations: [{
 43        type: mongoose.Schema.Types.ObjectId,
 44        ref: 'conversationModel'
 45    }],
 46    diets: [{
 47        type: mongoose.Schema.Types.ObjectId,
 48        ref: 'dietModel'
 49    }],
 50    trainers: [{
 51        type: mongoose.Schema.Types.ObjectId,
 52        ref: 'userModel'
 53    }],
 54    routines: [{
 55        type: mongoose.Schema.Types.ObjectId,
 56        ref: 'routineModel'
 57    }],// trainermodel
 58    disciplines : [{
 59        name: {type: String}
 60    }],
 61    specialties : [{
 62        name: {type: String}
 63    }],
 64    clients: [{
 65      client: {
 66        type: mongoose.Schema.Types.ObjectId,
 67        ref: 'userModel'
 68      },
 69      petitionMessage: {type: String},
 70      date: {type: Date}
 71    }],
 72    clientsPetitions: [{
 73      clientid: {
 74          type: mongoose.Schema.Types.ObjectId,
 75          ref: 'userModel'
 76      },
 77      message: {type: String},
 78      state: {type: String}//pendent, accepted, declined
 79    }],
 80    valoration:  {type:String}, //La media de todas las valoraciones
 81    valorations: [{
 82      clientid: {
 83          type: mongoose.Schema.Types.ObjectId,
 84          ref: 'userModel'
 85      },
 86      date: {type: Date},
 87      message: {type: String},//missatge de valoració
 88      value: {type: Number}//per exemple sistema d'estrelles sobre 5
 89    }],//end of trainermodel
 90    points: {
 91        total: {type: Number},
 92        history: [{
 93            concept: {type: String},
 94            date: {type: Date},
 95            value: {type: Number}
 96        }]
 97    },
 98    marks: [{
 99        title: {type: String},
100        unit: {type: String},//si són kg, km
101        best: {
102            date: {type: Date},
103            value: {type: String}
104        },
105        days:[{
106            date: {type: Date},
107            value: {type: String}
108        }]
109    }],
110    notifications: [{
111        state: {type: String},//viewed, pendent
112        message: {type: String},
113        link: {type: String},//aquí oju, a la app i a la web calen links diferents, però ho podem fer posant sempre a la app i a la web el prefix del link (#!/app) o (#/app/), i després afegint-hi la pàgina on volem enviar el routing, per exemple (dashboard)
114        icon: {type: String},
115        date: {type: Date},
116        dateviewed: {type: Date}
117    }],
118    followers: [{
119        type: mongoose.Schema.Types.ObjectId,
120        ref: 'userModel'
121    }],
122    following: [{
123        type: mongoose.Schema.Types.ObjectId,
124        ref: 'userModel'
125    }],
126    google: {
127        id: {type: String},
128        token: {type: String},
129        email: {type: String},
130        name: {type: String},
131    },
132    twitter: {
133        id: {type: String},
134        token: {type: String},
135        email: {type: String},
136        name: {type: String},
137    }
138});
139userSchema.plugin(mongooseUniqueValidator);
140module.exports = mongoose.model('userModel', userSchema);