From beb24e45b6ea43bb7f89b38631047df17a9931df Mon Sep 17 00:00:00 2001 From: kumar Date: Sat, 23 Jul 2016 21:38:32 -0400 Subject: added update vote count of solutions --- node_simple.js | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) (limited to 'node_simple.js') diff --git a/node_simple.js b/node_simple.js index 58a114b..f57b3aa 100644 --- a/node_simple.js +++ b/node_simple.js @@ -11,7 +11,7 @@ * 5. solutions ? CURRENTLY WORKING ON -- need to add field for solutions provider, and updating. * 7. add university field to courses, exams ? PENDING * 8. make a user ? DONE - * 9. + * 9. update user info when they comment or post a solution ? PENDING * */ @@ -482,7 +482,7 @@ exports.get_exam_info_by_ID = function (exam_id, callback) { /* * This function will add a comment to the solutions table * Params: sol_id - id of the solution to which to add the comment - * fields - [text, by] + * fields - [text, by_username] * */ exports.add_comment = function (sol_id, fields) { var Data = { @@ -581,6 +581,32 @@ exports.add_solution = function (fields, callback) { }; + + + +exports.vote_solution = function (sol_id, upORdown , callback) { + var vote = (upORdown == "up") ? 1 : -1; + + mongoFactory.getConnection(uri).then(function (db) { + var solutions = db.collection('solutions'); + solutions.updateOne( + {_id: ObjectId(sol_id) }, + { $inc: { votes: vote} }, function (err) { + // if (err) throw err; + if (err) callback(false, "Error: couldnt update the vote count"); + else { + callback(true, "Success: updated vote count"); + } + }); + db.close(); + }).catch(function (err) { + console.log(err); + }); +}; + + + + /* * This function will retrieve all exams in the database given the course code ... * ... ordered by the year of the exam. -- cgit v1.2.3 From 64d9ccb6ae21a12d6fbd61b371397d8d5f2e783f Mon Sep 17 00:00:00 2001 From: nanalelfe Date: Sat, 23 Jul 2016 23:10:00 -0400 Subject: need pull --- node_simple.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'node_simple.js') diff --git a/node_simple.js b/node_simple.js index 65a233c..fe045d2 100644 --- a/node_simple.js +++ b/node_simple.js @@ -83,6 +83,7 @@ var assert = require('assert'); // Standard URI format: mongodb://[dbuser:dbpassword@]host:port/dbname var uri = exports.uri = 'mongodb://general:assignment4@ds057862.mlab.com:57862/solutions_repo'; + // Keep this for testing on local machine, do not remove. - Humair //var uri = 'mongodb://localhost:27017/db'; @@ -473,8 +474,6 @@ exports.get_all_solutions = function (exam_id, q_num, callback) { .catch(function () { console.error(err); }) - - }; /* -- cgit v1.2.3 From cbcf2f83d7a11895deeb1234504dd767d8826d4d Mon Sep 17 00:00:00 2001 From: kumar Date: Sat, 23 Jul 2016 23:32:57 -0400 Subject: updated todo lst --- node_simple.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'node_simple.js') diff --git a/node_simple.js b/node_simple.js index f57b3aa..e18839b 100644 --- a/node_simple.js +++ b/node_simple.js @@ -6,12 +6,16 @@ * 2. add upload date and user name ? DONE * 3. remove exam ? DONE * 4a. get all questions for a given exam_id ? DONE - * 4b. add exam id to each question returned. ? PENDING + * 4b. add exam id to each question returned. ? NO NEED * 6. get all solutions provided question_id and exam_id ? DONE - * 5. solutions ? CURRENTLY WORKING ON -- need to add field for solutions provider, and updating. + * 5. solutions ? DONE -- need to add field for solutions provider, and updating. DONE * 7. add university field to courses, exams ? PENDING * 8. make a user ? DONE * 9. update user info when they comment or post a solution ? PENDING + * 10. comment_history ? DONE + * 11. solutions_history ? DONE + * 12. voting for solutions ? DONE + * * */ -- cgit v1.2.3