aboutsummaryrefslogtreecommitdiff
path: root/node_simple.js
diff options
context:
space:
mode:
authornanalelfe <nargiza.nosirova@mail.utoronto.ca>2016-07-24 00:54:48 +0000
committernanalelfe <nargiza.nosirova@mail.utoronto.ca>2016-07-24 00:54:48 +0000
commitdbdcb21969ffd5540bd310b14ee2348adac24b5c (patch)
tree2dd748f9655cc147051e12aa5879174913204b4d /node_simple.js
parent17d743822746b047b94cd24e5407f1342ba01a7e (diff)
Added comments for user, along with dummy data if the user doesn't have any comments
Diffstat (limited to 'node_simple.js')
-rw-r--r--node_simple.js24
1 files changed, 17 insertions, 7 deletions
diff --git a/node_simple.js b/node_simple.js
index 2c57d69..c3431ed 100644
--- a/node_simple.js
+++ b/node_simple.js
@@ -95,6 +95,10 @@ var uri = exports.uri = 'mongodb://general:assignment4@ds057862.mlab.com:57862/
// will add comments ASAP
+/* callback(success, data/message) => callback(boolean, object/String);
+ *
+ *
+ */
exports.retrieve_userComments_history = function (username, callback) {
// get a connection
@@ -117,7 +121,7 @@ exports.retrieve_userComments_history = function (username, callback) {
_id: 0
}}
]).toArray(function (err, results) {
- if (err) callback(false, "Error: some wierd error occured while query");
+ if (err) callback(false, "Error: some weird error occurred while query");
else {
callback(true, results);
}
@@ -135,7 +139,7 @@ exports.retrieve_userComments_history = function (username, callback) {
exports.retrieve_userComments_count = function (username, callback) {
exports.retrieve_userComments_history(username, function (bool, results) {
- if (!bool) callback(false, "Error: error occured");
+ if (!bool) callback(false, "Error: error occurred");
else {
var length = results.length;
callback(true, length);
@@ -828,9 +832,10 @@ exports.remove_exam = function (fields, serverCallback) {
});
};
-//get_exam_byID("578a44ff71ed097fc3079d6e");
-exports.get_exam_byID = function (id) {
+
+// callback(success, error, data)
+exports.get_exam_byID = function (id, callback) {
// establish a connection
mongoFactory.getConnection(uri)
@@ -840,15 +845,20 @@ exports.get_exam_byID = function (id) {
var exams = db.collection('exams');
// query
exams.find( {_id: ObjectId(id)} ).toArray(function (err, docs) {
- if (err) throw err;
+ if (err) {
+ callback(false, true, null);
+ } else if (!docs) {
+ callback(false, false, null);
+ }
else {
// console.log(JSON.stringify(docs, null, 2));
- console.log(docs);
+ //console.log(docs);
+ callback(true, false, docs[0]);
}
});
})
.catch(function(err) {
- console.error(err);
+ callback(false, true, null);
});
};