From 4ce98375d61429f2e41cfefe884df4f0640dd0a2 Mon Sep 17 00:00:00 2001 From: kumar Date: Sun, 24 Jul 2016 23:02:05 -0400 Subject: added exam info along with the comments histroy --- node_simple.js | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) (limited to 'node_simple.js') diff --git a/node_simple.js b/node_simple.js index 3c3abd7..b377bac 100644 --- a/node_simple.js +++ b/node_simple.js @@ -89,6 +89,7 @@ var mongodb = exports.mongodb = require('mongodb'); var mongoFactory = exports.mongoFactory = require('mongo-factory'); var ObjectId = require('mongodb').ObjectID; var assert = require('assert'); +var _ = require('underscore'); // Standard URI format: mongodb://[dbuser:dbpassword@]host:port/dbname var uri = exports.uri = 'mongodb://general:assignment4@ds057862.mlab.com:57862/solutions_repo'; @@ -337,6 +338,8 @@ exports.retrieve_userComments_history = function (username, callback) { mongoFactory.getConnection(uri).then(function (db) { var solutions = db.collection('solutions'); + var exams = db.collection('exams'); + var mylist = []; solutions.aggregate([ { $match : { @@ -352,14 +355,24 @@ exports.retrieve_userComments_history = function (username, callback) { exam_id: "$exam_id", _id: 0 }} - ]).toArray(function (err, results) { - if (err) callback(false, "Error: some weird error occurred while query"); - else { - callback(true, results); - } - + ]).toArray(function (err, res) { + var finised = _.after(res.length, doCall); // execute "doCall" only after res.length # of attempts + res.forEach(function (comment) { + exams.find( { _id: ObjectId(comment.exam_id) } ).toArray(function (err, docs) { // get the exam info + comment.course_code = docs[0].course_code; + comment.year = docs[0].year; + comment.term = docs[0].term; + mylist.push(comment); // save it to array + finised(); + }); + }); }); + function doCall() { + callback(true, mylist); + } + + }).catch(function (err) { // console.err(err); callback(false, "Error: failed to connect to db"); -- cgit v1.2.3 From 34f553940cd5e9fba5ca6062333f42ba741b700a Mon Sep 17 00:00:00 2001 From: nanalelfe Date: Sun, 24 Jul 2016 23:14:34 -0400 Subject: Fixed /send_message error/success message show up. --- node_simple.js | 1 + 1 file changed, 1 insertion(+) (limited to 'node_simple.js') diff --git a/node_simple.js b/node_simple.js index 3c3abd7..d2586e8 100644 --- a/node_simple.js +++ b/node_simple.js @@ -1207,6 +1207,7 @@ exports.get_exam_byID = function (id, callback) { } else { callback(true, false, docs[0]); + console.log("DOCS: "+ docs); } }); }) -- cgit v1.2.3