Advertisement
Guest User

Untitled

a guest
Oct 12th, 2017
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.71 KB | None | 0 0
  1. var UserSchema = new mongoose.Schema({
  2. firstName: String,
  3. lastName: String,
  4. image: {
  5. type: String,
  6. default: "http://via.placeholder.com/250x200"
  7. },
  8. email: {
  9. type: String,
  10. required: [true, "Email missing."],
  11. unique: true
  12. },
  13. kind: {
  14. type: String,
  15. enum: ["Admin", "Teacher", "Student"],
  16. default: "Student"
  17. },
  18. isAdmin: {
  19. type: Boolean,
  20. default: false
  21. },
  22. isPromote: {
  23. type: Boolean,
  24. default: false
  25. },
  26. username: {
  27. type: String,
  28. required: [true, "Username missing."],
  29. unique: true
  30. },
  31. password: String
  32. }, options);
  33.  
  34. UserSchema.plugin(passportLocalMongoose);
  35.  
  36. module.exports = mongoose.model("User", UserSchema);
  37.  
  38. var options = {discriminatorKey: 'kind'};
  39. var StudentSchema = new mongoose.Schema({
  40. indexNumber: String,
  41. }, options);
  42.  
  43. module.exports = User.discriminator("Student", StudentSchema);
  44.  
  45. var CourseSchema = new mongoose.Schema({
  46. teachers: [{
  47. type: mongoose.Schema.Types.ObjectId,
  48. ref: "Teacher"
  49. }],
  50. students: [{
  51. id: {
  52. type: mongoose.Schema.Types.ObjectId,
  53. ref: "Student"
  54. },
  55. entryDate: {
  56. type: Date,
  57. default: Date.now
  58. }
  59. }]
  60.  
  61. Course.findById(req.params.id)
  62. .populate("students.id")
  63. .populate("teachers")
  64. .exec( function(err, foundCourse) {...}
  65.  
  66. students: [ { _id: 59dbd1259df328279cd5d588, entryDate: 2017-10-12T22:29:48.297Z }, { _id: 59dc07088c6fd636188d87c5, entryDate: 2017-10-12T22:29:48.297Z } ], teachers: [ { _id: 59dbc34832b0041b44a7f648, isPromote: false, isAdmin: false, kind: 'Teacher', image: 'http://via.placeholder.com/250x200' } ]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement