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 ) {
users : Array
});
+SchoolSchema.virtual( 'sanitized' ).get(function() {
+ var school = {
+ _id: this._id,
+ name: this.name,
+ description: this.description,
+ url: this.url
+ }
+
+ return school;
+})
+
SchoolSchema.method( 'authorize', function( user, cb ) {
return cb(user.admin || ( this.users.indexOf( user._id ) !== -1 ));
});
// XXX: room for additional resources
created : { type : Date, default : Date.now },
creator : ObjectId,
+ deleted : Boolean,
// many users may subscribe to a course
users : Array
});
+CourseSchema.virtual( 'sanitized' ).get(function() {
+ var course = {
+ _id: this._id,
+ name: this.name,
+ number: this.number || 'None',
+ description: this.description || 'None',
+ subject: this.subject || 'None',
+ department: this.department || 'None'
+ }
+
+ return course;
+});
+
CourseSchema.virtual( 'displayName' )
.get( function() {
if( this.number ) {
var id = this._id;
Course.collection.update( { '_id' : id }, { '$set' : { 'deleted' : true } }, function( err ) {
- callback( err );
+ if (callback) callback( err );
+ Lecture.find( { course: id }, function( err, lectures) {
+ if (lectures.length > 0) {
+ lectures.forEach(function(lecture) {
+ lecture.delete();
+ })
+ }
+ })
})
});
date : { type : Date, default: Date.now },
live : Boolean,
creator : ObjectId,
+ deleted : Boolean,
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) {
});
});
+LectureSchema.method( 'delete', function( callback ) {
+ var id = this._id;
+
+ Lecture.collection.update( { '_id' : id }, { '$set' : { 'deleted' : true } }, function( err ) {
+ if (callback) callback( err );
+ Note.find( { lecture : id }, function(err, notes) {
+ notes.forEach(function(note) {
+ note.delete();
+ })
+ })
+ Post.find( { lecture : id }, function(err, posts) {
+ posts.forEach(function(post) {
+ post.delete();
+ })
+ })
+ })
+});
+
var Lecture = mongoose.model( 'Lecture', LectureSchema );
// notes
visits : Number,
created : { type : Date, default : Date.now },
creator : ObjectId,
+ deleted : Boolean,
lecture : ObjectId,
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) {
Note.collection.update( { '_id' : id }, { '$inc' : { 'visits' : 1 } } );
});
+NoteSchema.method( 'delete', function( callback ) {
+ var id = this._id;
+
+ Note.collection.update( { '_id' : id }, { '$set' : { 'deleted' : true } }, function( err ) {
+ if (callback) callback( err );
+ })
+});
+
var Note = mongoose.model( 'Note', NoteSchema );
// comments
comments : Array,
- lecture : String // ObjectId
+ lecture : String, // ObjectId
+ deleted : Boolean
})
-mongoose.model( 'Post', PostSchema );
-
-
-// Deleted documents
-
-var DeletedCourse = new Schema( {
- name : { type : String, required : true },
- number : String,
- description : String,
- instructor : ObjectId,
- // courses are tied to one school
- school : ObjectId,
-
- // XXX: room for additional resources
- created : { type : Date, default : Date.now },
- creator : ObjectId,
-
- // many users may subscribe to a course
- users : Array
-});
-
-
-mongoose.model( 'DeletedCourse', DeletedCourse )
-
-var DeletedLecture = new Schema( {
- name : { type : String, required : true },
- date : { type : Date, default: Date.now },
- live : Boolean,
- creator : ObjectId,
-
- course : ObjectId
-});
-
-
-mongoose.model( 'DeletedLecture', DeletedLecture )
-
-var DeletedNote = new Schema( {
- name : { type : String, required : true },
- path : String,
- public : Boolean,
- roID : String,
- visits : Number,
- created : { type : Date, default : Date.now },
- creator : ObjectId,
-
- lecture : ObjectId,
+PostSchema.method( 'delete', function( callback ) {
+ var id = this._id;
- collaborators : [String]
+ Post.collection.update( { '_id' : id }, { '$set' : { 'deleted' : true } }, function( err ) {
+ if (callback) callback( err );
+ })
});
-
-mongoose.model( 'DeletedNote', DeletedNote )
-
-var DeletedPost = new Schema({
- date : { type : Date, default : Date.now },
- body : String,
- votes : [String],
- reports : [String],
- public : Boolean,
-
- userid : String, // ObjectId,
- userName : String,
- userAffil : String,
-
- comments : Array,
-
- lecture : String // ObjectId
-})
-
-
-mongoose.model( 'DeletedPost', DeletedPost )
-
+mongoose.model( 'Post', PostSchema );
var ArchivedCourse = new Schema({
id: Number,
text: String
})
+ArchivedNote.virtual( 'sanitized' ).get(function() {
+ var note = {
+ _id: this._id,
+ topic: this.topic === '' ? (this.text.replace(/(<(.|\n)*?>)|[\r\n\t]*/g, '')).substr(0, 15) + '...' : this.topic
+ }
+ return note;
+})
+
mongoose.model( 'ArchivedNote', ArchivedNote )
var ArchivedSubject = new Schema({