aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--node_simple.js30
-rw-r--r--testImports.js9
2 files changed, 35 insertions, 4 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.
diff --git a/testImports.js b/testImports.js
index 8946a2f..7546f06 100644
--- a/testImports.js
+++ b/testImports.js
@@ -115,12 +115,12 @@ dbFile.retrieve_userSolutions_count("some_user name", function (bool, result) {
});*/
-dbFile.followExam("nanalelfe@gmail.com", "578a44ff71ed097fc3079d6e", function (bool, mssg) {
+/*dbFile.followExam("nanalelfe@gmail.com", "578a44ff71ed097fc3079d6e", function (bool, mssg) {
if (!bool) console.log(mssg);
else {
console.log(mssg);
}
-});
+});*/
/*
dbFile.retrieveFollows("some_user names", function (bool, result) {
@@ -129,3 +129,8 @@ dbFile.retrieveFollows("some_user names", function (bool, result) {
console.log(result);
}
});*/
+
+
+/*dbFile.vote_solution("5792d8a970040378d4e4b389" , "down", function (bool, mssg) {
+ console.log(mssg);
+});*/