From 98c9cbc6258f699fc944f025230c35faf8575bc2 Mon Sep 17 00:00:00 2001 From: kdam0 Date: Mon, 30 Jan 2017 00:02:09 -0500 Subject: feat. added auto fill for search bar. --- node_simple.js | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) (limited to 'node_simple.js') diff --git a/node_simple.js b/node_simple.js index 2f49360..e991515 100644 --- a/node_simple.js +++ b/node_simple.js @@ -117,6 +117,7 @@ var uri = exports.uri = 'mongodb://general:assignment4@ds057862.mlab.com:57862/ exports.setupDB = function (callback) { mongoFactory.getConnection(uri).then(function (database) { db = database; + // var corses = exports.find_all_course_codes_from_exams(); callback(true, "Database connected"); // signal start of app }).catch(function (err) { @@ -648,6 +649,28 @@ exports.updatePassword = function (email, password, callback) { /************************* COURSES / EXAMS **********************************/ + +/** + * Find all UNIQUE course codes from EXAMS collection + * + * @param {function} callback: 2 args: (), + * where : couseCodes array + */ +exports.find_all_course_codes_from_exams = function (callback) { + var exams = db.collection('exams'); + exams.distinct("course_code", function (err, result) { + if (err) throw console.log(err); + else { + // console.log(result); + callback(result); + } + }); + + // callback(unique_coursecodes.distinct('course_code')); + // return (unique_coursecodes.distinct('course_code')); +}; + + /** * Remvove a course from ONLY the courses table IN CASE of accidental * addition. @@ -1435,4 +1458,4 @@ exports.getNotifications = function(email, callback) { }); -} \ No newline at end of file +} -- cgit v1.2.3 From e78238959da75e4574bb4bbd4dc1c4433d02785b Mon Sep 17 00:00:00 2001 From: kdam0 Date: Wed, 1 Feb 2017 20:55:12 -0500 Subject: better error handling and clean up --- node_simple.js | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'node_simple.js') diff --git a/node_simple.js b/node_simple.js index e991515..1061464 100644 --- a/node_simple.js +++ b/node_simple.js @@ -117,7 +117,6 @@ var uri = exports.uri = 'mongodb://general:assignment4@ds057862.mlab.com:57862/ exports.setupDB = function (callback) { mongoFactory.getConnection(uri).then(function (database) { db = database; - // var corses = exports.find_all_course_codes_from_exams(); callback(true, "Database connected"); // signal start of app }).catch(function (err) { @@ -659,10 +658,9 @@ exports.updatePassword = function (email, password, callback) { exports.find_all_course_codes_from_exams = function (callback) { var exams = db.collection('exams'); exams.distinct("course_code", function (err, result) { - if (err) throw console.log(err); + if (err) callback(false, "Failed to get unique courses"); else { - // console.log(result); - callback(result); + callback(true, result); } }); -- cgit v1.2.3 From c1bcbbec851d509ee911016536a5e684eac4ee43 Mon Sep 17 00:00:00 2001 From: kdam0 Date: Wed, 1 Feb 2017 20:58:03 -0500 Subject: some more cleanup --- node_simple.js | 3 --- 1 file changed, 3 deletions(-) (limited to 'node_simple.js') diff --git a/node_simple.js b/node_simple.js index 1061464..f07c0e8 100644 --- a/node_simple.js +++ b/node_simple.js @@ -663,9 +663,6 @@ exports.find_all_course_codes_from_exams = function (callback) { callback(true, result); } }); - - // callback(unique_coursecodes.distinct('course_code')); - // return (unique_coursecodes.distinct('course_code')); }; -- cgit v1.2.3