Advertisement
dllo4147

add function

Oct 23rd, 2014
170
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.79 KB | None | 0 0
  1. add: function (req, res) {
  2. var id = req.session.Student.id;
  3. Student.findOne({id: id}).exec(function(err, thisStudent) {
  4. Course.findOne({unit_code: req.param('unit_code')}).exec(function(err, thisCourse) {
  5. var creditPoints = thisCourse.credit_points;
  6. for (i = 0; i < thisStudent.courses.length; i++) {
  7. creditPoints = creditPoints + parseInt(thisStudent.courses[i].credit_points)
  8. console.log("in for loop cp is " + creditPoints);
  9. }
  10.  
  11. if (creditPoints > 12) {
  12. res.redirect('/exceeded_credit_points');
  13. }
  14.  
  15. else {
  16. console.log("credit points is " + creditPoints);
  17. thisStudent.courses.add(thisCourse);
  18. thisStudent.save(function(err, newStudent){});
  19. res.view({
  20. course: thisCourse
  21. });
  22. }
  23. });
  24. });
  25. },
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement