fix merge conflict
authorchapel <jacob.chapel@gmail.com>
Mon, 14 Nov 2011 23:44:11 +0000 (15:44 -0800)
committerchapel <jacob.chapel@gmail.com>
Mon, 14 Nov 2011 23:44:11 +0000 (15:44 -0800)
1  2 
app.js

diff --combined app.js
index bda679382400c0d60f4a1b1f0cd70a8f5ac849f3,cb332c384d760c4c6b0f54a073b27e27dbb4ccad..c94efaed7bd56c8ec0324494f44fec7f8b692282
--- 1/app.js
--- 2/app.js
+++ b/app.js
@@@ -1548,7 -1548,7 +1548,7 @@@ app.post( '/profile', loadUser, loggedI
  function loadSubject( req, res, next ) {
    if( url.parse( req.url ).pathname.match(/subject/) ) {
      ArchivedSubject.findOne({id: req.params.id }, function(err, subject) {
 -      if ( err ) {
 +      if ( err || !subject) {
          sendJson(res,  {status: 'error', message: 'Subject with this ID does not exist'} )
        } else {
          req.subject = subject;
  function loadOldCourse( req, res, next ) {
    if( url.parse( req.url ).pathname.match(/course/) ) {
      ArchivedCourse.findOne({id: req.params.id }, function(err, course) {
 -      if ( err ) {
 +      if ( err || !course ) {
          sendJson(res,  {status: 'error', message: 'Course with this ID does not exist'} )
        } else {
          req.course = course;
@@@ -1603,7 -1603,7 +1603,7 @@@ app.get( '/learn/random', loadUser, fun
  
  app.get( '/archive', checkAjax, loadUser, function( req, res ) {
    ArchivedSubject.find({}).sort( 'name', '1' ).run( function( err, subjects ) {
 -    if ( err ) {
 +    if ( err || subjects.length === 0) {
        sendJson(res,  {status: 'error', message: 'There was a problem gathering the archived courses, please try again later.'} );
      } else {
        sendJson(res,  { 'subjects' : subjects, 'user': req.user.sanitized } );
  
  app.get( '/archive/subject/:id', checkAjax, loadUser, loadSubject, function( req, res ) {
    ArchivedCourse.find({subject_id: req.params.id}).sort('name', '1').run(function(err, courses) {
 -    if ( err ) {
 +    if ( err || courses.length === 0 ) {
        sendJson(res,  {status: 'error', message: 'There are no archived courses'} );
      } else {
        sendJson(res,  { 'courses' : courses, 'subject': req.subject, 'user': req.user.sanitized } );
  
  app.get( '/archive/course/:id', checkAjax, loadUser, loadOldCourse, function( req, res ) {
    ArchivedNote.find({course_id: req.params.id}).sort('name', '1').run(function(err, notes) {
 -    if ( err ) {
 +    if ( err || notes.length === 0) {
        sendJson(res,  {status: 'error', message: 'There are no notes in this course'} );
      } else {
 -      sendJson(res,  { 'notes' : notes, 'course' : req.course, 'user': req.user.sanitized } );
 +      notes = notes.map(function(note) { return note.sanitized });
 +      sendJson(res,  { 'notes': notes, 'course' : req.course, 'user': req.user.sanitized } );
      }
    })
  })
  
  app.get( '/archive/note/:id', checkAjax, loadUser, function( req, res ) {
+   console.log( "id="+req.params.id)
    ArchivedNote.findById(req.params.id, function(err, note) {
 -    if ( err ) {
 -      sendJson(res,  {status: 'error', message: 'This is not a valid id for a note', err:err } );
 +    if ( err || !note ) {
 +      sendJson(res,  {status: 'error', message: 'This is not a valid id for a note'} );
      } else {
        ArchivedCourse.findOne({id: note.course_id}, function(err, course) {
 -        if ( err ) {
 +        if ( err || !course ) {
            sendJson(res,  {status: 'error', message: 'There is no course for this note'} )
          } else {
            sendJson(res,  { 'layout' : 'notesLayout', 'note' : note, 'course': course, 'user': req.user.sanitized } );