Convert other data points to ajax
[oweals/finalsclub.git] / models.js
index f9bea517884dc5cd846eaf2457a6e85a1dadbea9..e05e4d135bf02b72ebdf915cf5536e095f387b3c 100644 (file)
--- a/models.js
+++ b/models.js
@@ -36,6 +36,18 @@ var UserSchema = new Schema( {
        admin                                           : { 'type' : Boolean, 'default' : false }
 });
 
+UserSchema.virtual( 'sanitized' ).get(function() {
+  var user = {
+    email: this.email,
+    name: this.name,
+    affil: this.affil,
+    showName: this.showName,
+    admin: this.admin
+  }
+
+  return user;
+});
+
 UserSchema.virtual( 'displayName' )
        .get( function() {
                if( this.showName ) {
@@ -253,6 +265,17 @@ var LectureSchema  = new Schema( {
        course                          : ObjectId
 });
 
+LectureSchema.virtual( 'sanitized' ).get(function() {
+  var lecture = {
+    _id: this._id,
+    name: this.name,
+    date: this.date,
+    live: this.live
+  }
+
+  return lecture;
+})
+
 LectureSchema.method( 'authorize', function( user, cb ) {
        Course.findById( this.course, function( err, course ) {
                if (course) {
@@ -302,6 +325,19 @@ var NoteSchema = new Schema( {
        collaborators : [String]
 });
 
+NoteSchema.virtual( 'sanitized').get(function() {
+  var note = {
+    _id: this._id,
+    name: this.name,
+    path: this.path,
+    public: this.public,
+    roID: this.roID,
+    visits: this.visits
+  }
+
+  return note;
+});
+
 NoteSchema.method( 'authorize', function( user, cb ) {
        Lecture.findById( this.lecture, function( err, lecture ) {
                if (lecture) {