Send none if a course variable is missing
[oweals/finalsclub.git] / models.js
index e05e4d135bf02b72ebdf915cf5536e095f387b3c..15b812521b5b662a9a3dce6143b83408d7483629 100644 (file)
--- a/models.js
+++ b/models.js
@@ -186,10 +186,10 @@ CourseSchema.virtual( 'sanitized' ).get(function() {
   var course = {
     _id: this._id,
     name: this.name,
-    number: this.number,
-    description: this.description,
-    subject: this.subject,
-    department: this.department
+    number: this.number || 'None',
+    description: this.description || 'None',
+    subject: this.subject || 'None',
+    department: this.department || 'None'
   }
 
   return course;
@@ -412,6 +412,14 @@ var ArchivedNote = new Schema({
   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({