From d6cdfdf0dc6e760086c3b943f5cdf79a4b1b07c0 Mon Sep 17 00:00:00 2001 From: Seth Woodworth Date: Sun, 22 Jan 2012 19:44:05 -0500 Subject: [PATCH] adding course count to app and template schools page --- app.js | 18 +++++++++++++++--- public/index.html | 2 +- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/app.js b/app.js index fef3b7f..da9ed2c 100644 --- a/app.js +++ b/app.js @@ -563,16 +563,28 @@ app.get( '/schools', checkAjax, loadUser, function( req, res ) { // XXX mongoose's documentation on sort is extremely poor, tread carefully School.find( {} ).sort( 'name', '1' ).run( function( err, schools ) { if( schools ) { - // If schools are found, loop through them gathering any courses that are // associated with them and then render the page with that information. var schools_todo = schools.length; - schools.each(function (school) { + schools.map(function (school) { + sys.puts("making course query"); Course.find( { 'school': school.id } ).run(function (err, courses) { school.courses_length = courses.length schools_todo -= 1; if (schools_todo <= 0) { - sendJson(res, { 'user': user.sanitized, 'schools': schools }); + sendJson(res, { 'user': user.sanitized, 'schools': schools.map( function(s) { + sys.puts("here"); + var school = { + _id: s._id, + name: s.name, + description: s.description, + url: s.url, + slug: s.slug, + courses: s.courses_length + }; + return school; + }) + }); } }); }); diff --git a/public/index.html b/public/index.html index 38a74eb..e964aa5 100644 --- a/public/index.html +++ b/public/index.html @@ -170,7 +170,7 @@
${name} - 12 Courses, + ${courses} Courses, 27 Notes
-- 2.25.1