aboutsummaryrefslogtreecommitdiff
path: root/node_simple.js
diff options
context:
space:
mode:
Diffstat (limited to 'node_simple.js')
-rw-r--r--node_simple.js25
1 files changed, 16 insertions, 9 deletions
diff --git a/node_simple.js b/node_simple.js
index 26cbbe4..58a114b 100644
--- a/node_simple.js
+++ b/node_simple.js
@@ -158,6 +158,10 @@ exports.retrieveFollows = function (user_name, callback) {
// will add comments ASAP
+/* callback(success, data/message) => callback(boolean, object/String);
+ *
+ *
+ */
exports.retrieve_userComments_history = function (username, callback) {
// get a connection
@@ -180,7 +184,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);
}
@@ -198,7 +202,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);
@@ -891,9 +895,8 @@ exports.remove_exam = function (fields, serverCallback) {
});
};
-//get_exam_byID("578a44ff71ed097fc3079d6e");
-
-exports.get_exam_byID = function (id, serverCallback) {
+// callback(success, error, data)
+exports.get_exam_byID = function (id, callback) {
// establish a connection
mongoFactory.getConnection(uri)
@@ -903,15 +906,19 @@ exports.get_exam_byID = function (id, serverCallback) {
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 {
- serverCallback(docs[0]);
- //console.log(docs);
+ callback(true, false, docs[0]);
+
}
});
})
.catch(function(err) {
- console.error(err);
+ callback(false, true, null);
});
};