aboutsummaryrefslogtreecommitdiff
path: root/node_simple.js
diff options
context:
space:
mode:
authorkumar <kumar.damani@mail.utoronto.ca>2016-07-24 01:38:32 +0000
committerkumar <kumar.damani@mail.utoronto.ca>2016-07-24 01:38:32 +0000
commitbeb24e45b6ea43bb7f89b38631047df17a9931df (patch)
tree59f0bf7a94e308f2da922e61f6472dfaae8f20ce /node_simple.js
parent8f6bfa9244411274c4f6a489b2571a423f7d8548 (diff)
added update vote count of solutions
Diffstat (limited to 'node_simple.js')
-rw-r--r--node_simple.js30
1 files changed, 28 insertions, 2 deletions
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.