From d7b7979ee012dde10feae7d64e53fde2847aaf89 Mon Sep 17 00:00:00 2001 From: HumairAK Date: Sun, 24 Jul 2016 16:45:03 -0400 Subject: added comments to frient-end --- node_simple.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'node_simple.js') diff --git a/node_simple.js b/node_simple.js index 8e7620f..003d4a8 100644 --- a/node_simple.js +++ b/node_simple.js @@ -684,7 +684,7 @@ exports.get_exam_info_by_ID = function (exam_id, callback) { * Params: sol_id - id of the solution to which to add the comment * fields - <[text, by_username]> * */ -exports.add_comment = function (sol_id, fields) { +exports.add_comment = function (sol_id, fields, serverCallback) { var Data = { text: fields[0], date: new Date(), @@ -698,14 +698,19 @@ exports.add_comment = function (sol_id, fields) { var solutions = db.collection('solutions'); // insert data into table solutions.updateOne( {_id: ObjectId(sol_id)}, {$push: {comments: Data}} , function (err, result) { - if (err) throw err; + if (err) { + ServerCallback(false, "Error: Solution found, but could not update comments."); + throw err; + } else { + serverCallback(true, "Comment added successfully"); console.log("comment added"); } }); }) .catch(function (err) { + serverCallback(false, "Error: Could not establish connection with database."); console.error(err); }) }; -- cgit v1.2.3