diff options
| -rw-r--r-- | node_modules/underscore/package.json | 111 | ||||
| -rw-r--r-- | node_simple.js | 25 | ||||
| -rw-r--r-- | package.json | 3 | ||||
| -rw-r--r-- | testImports.js | 15 |
4 files changed, 60 insertions, 94 deletions
diff --git a/node_modules/underscore/package.json b/node_modules/underscore/package.json index 41b4189..44e6afc 100644 --- a/node_modules/underscore/package.json +++ b/node_modules/underscore/package.json @@ -1,53 +1,24 @@ { - "_args": [ - [ - { - "name": "underscore", - "raw": "underscore@^1.8.3", - "rawSpec": "^1.8.3", - "scope": null, - "spec": ">=1.8.3 <2.0.0", - "type": "range" - }, - "/Users/warefhaque/CSC309/solutions_repo/node_modules/mongo-factory" - ] - ], - "_from": "underscore@>=1.8.3 <2.0.0", - "_id": "underscore@1.8.3", - "_inCache": true, - "_installable": true, - "_location": "/underscore", - "_npmUser": { - "email": "jashkenas@gmail.com", - "name": "jashkenas" - }, - "_npmVersion": "1.4.28", - "_phantomChildren": {}, - "_requested": { - "name": "underscore", - "raw": "underscore@^1.8.3", - "rawSpec": "^1.8.3", - "scope": null, - "spec": ">=1.8.3 <2.0.0", - "type": "range" - }, - "_requiredBy": [ - "/mongo-factory" + "name": "underscore", + "description": "JavaScript's functional programming helper library.", + "homepage": "http://underscorejs.org", + "keywords": [ + "util", + "functional", + "server", + "client", + "browser" ], - "_resolved": "https://registry.npmjs.org/underscore/-/underscore-1.8.3.tgz", - "_shasum": "4f3fb53b106e6097fcf9cb4109f2a5e9bdfa5022", - "_shrinkwrap": null, - "_spec": "underscore@^1.8.3", - "_where": "/Users/warefhaque/CSC309/solutions_repo/node_modules/mongo-factory", "author": { - "email": "jeremy@documentcloud.org", - "name": "Jeremy Ashkenas" + "name": "Jeremy Ashkenas", + "email": "jeremy@documentcloud.org" }, - "bugs": { - "url": "https://github.com/jashkenas/underscore/issues" + "repository": { + "type": "git", + "url": "git://github.com/jashkenas/underscore.git" }, - "dependencies": {}, - "description": "JavaScript's functional programming helper library.", + "main": "underscore.js", + "version": "1.8.3", "devDependencies": { "docco": "*", "eslint": "0.6.x", @@ -56,48 +27,26 @@ "qunit-cli": "~0.2.0", "uglify-js": "2.4.x" }, - "directories": {}, - "dist": { - "shasum": "4f3fb53b106e6097fcf9cb4109f2a5e9bdfa5022", - "tarball": "https://registry.npmjs.org/underscore/-/underscore-1.8.3.tgz" + "scripts": { + "test": "npm run test-node && npm run lint", + "lint": "eslint underscore.js test/*.js", + "test-node": "qunit-cli test/*.js", + "test-browser": "npm i karma-phantomjs-launcher && ./node_modules/karma/bin/karma start", + "build": "uglifyjs underscore.js -c \"evaluate=false\" --comments \"/ .*/\" -m --source-map underscore-min.map -o underscore-min.js", + "doc": "docco underscore.js" }, + "license": "MIT", "files": [ "underscore.js", "underscore-min.js", "underscore-min.map", "LICENSE" ], - "gitHead": "e4743ab712b8ab42ad4ccb48b155034d02394e4d", - "homepage": "http://underscorejs.org", - "keywords": [ - "util", - "functional", - "server", - "client", - "browser" - ], - "license": "MIT", - "main": "underscore.js", - "maintainers": [ - { - "email": "jashkenas@gmail.com", - "name": "jashkenas" - } - ], - "name": "underscore", - "optionalDependencies": {}, - "readme": "ERROR: No README data found!", - "repository": { - "type": "git", - "url": "git://github.com/jashkenas/underscore.git" - }, - "scripts": { - "build": "uglifyjs underscore.js -c \"evaluate=false\" --comments \"/ .*/\" -m --source-map underscore-min.map -o underscore-min.js", - "doc": "docco underscore.js", - "lint": "eslint underscore.js test/*.js", - "test": "npm run test-node && npm run lint", - "test-browser": "npm i karma-phantomjs-launcher && ./node_modules/karma/bin/karma start", - "test-node": "qunit-cli test/*.js" + "readme": " __\n /\\ \\ __\n __ __ ___ \\_\\ \\ __ _ __ ____ ___ ___ _ __ __ /\\_\\ ____\n /\\ \\/\\ \\ /' _ `\\ /'_ \\ /'__`\\/\\ __\\/ ,__\\ / ___\\ / __`\\/\\ __\\/'__`\\ \\/\\ \\ /',__\\\n \\ \\ \\_\\ \\/\\ \\/\\ \\/\\ \\ \\ \\/\\ __/\\ \\ \\//\\__, `\\/\\ \\__//\\ \\ \\ \\ \\ \\//\\ __/ __ \\ \\ \\/\\__, `\\\n \\ \\____/\\ \\_\\ \\_\\ \\___,_\\ \\____\\\\ \\_\\\\/\\____/\\ \\____\\ \\____/\\ \\_\\\\ \\____\\/\\_\\ _\\ \\ \\/\\____/\n \\/___/ \\/_/\\/_/\\/__,_ /\\/____/ \\/_/ \\/___/ \\/____/\\/___/ \\/_/ \\/____/\\/_//\\ \\_\\ \\/___/\n \\ \\____/\n \\/___/\n\nUnderscore.js is a utility-belt library for JavaScript that provides\nsupport for the usual functional suspects (each, map, reduce, filter...)\nwithout extending any core JavaScript objects.\n\nFor Docs, License, Tests, and pre-packed downloads, see:\nhttp://underscorejs.org\n\nUnderscore is an open-sourced component of DocumentCloud:\nhttps://github.com/documentcloud\n\nMany thanks to our contributors:\nhttps://github.com/jashkenas/underscore/contributors\n", + "readmeFilename": "README.md", + "bugs": { + "url": "https://github.com/jashkenas/underscore/issues" }, - "version": "1.8.3" + "_id": "underscore@1.8.3", + "_from": "underscore@" } diff --git a/node_simple.js b/node_simple.js index d2586e8..f8eb07d 100644 --- a/node_simple.js +++ b/node_simple.js @@ -89,6 +89,7 @@ var mongodb = exports.mongodb = require('mongodb'); var mongoFactory = exports.mongoFactory = require('mongo-factory'); var ObjectId = require('mongodb').ObjectID; var assert = require('assert'); +var _ = require('underscore'); // Standard URI format: mongodb://[dbuser:dbpassword@]host:port/dbname var uri = exports.uri = 'mongodb://general:assignment4@ds057862.mlab.com:57862/solutions_repo'; @@ -337,6 +338,8 @@ exports.retrieve_userComments_history = function (username, callback) { mongoFactory.getConnection(uri).then(function (db) { var solutions = db.collection('solutions'); + var exams = db.collection('exams'); + var mylist = []; solutions.aggregate([ { $match : { @@ -352,14 +355,24 @@ exports.retrieve_userComments_history = function (username, callback) { exam_id: "$exam_id", _id: 0 }} - ]).toArray(function (err, results) { - if (err) callback(false, "Error: some weird error occurred while query"); - else { - callback(true, results); - } - + ]).toArray(function (err, res) { + var finised = _.after(res.length, doCall); // execute "doCall" only after res.length # of attempts + res.forEach(function (comment) { + exams.find( { _id: ObjectId(comment.exam_id) } ).toArray(function (err, docs) { // get the exam info + comment.course_code = docs[0].course_code; + comment.year = docs[0].year; + comment.term = docs[0].term; + mylist.push(comment); // save it to array + finised(); + }); + }); }); + function doCall() { + callback(true, mylist); + } + + }).catch(function (err) { // console.err(err); callback(false, "Error: failed to connect to db"); diff --git a/package.json b/package.json index 6b102af..9e23edc 100644 --- a/package.json +++ b/package.json @@ -40,5 +40,8 @@ "passport-local": "^1.0.0", "sanitizer": "^0.1.3", "socket.io": "^1.4.8" + }, + "devDependencies": { + "underscore": "~1.8.3" } } diff --git a/testImports.js b/testImports.js index 5a43034..aa044e0 100644 --- a/testImports.js +++ b/testImports.js @@ -58,18 +58,18 @@ var questions_array = ["this is q1", "this is q2"]; } });*/ -/*dbFile.retrieve_userComments_history("some_user name", function (bool, results) { +dbFile.retrieve_userComments_history("kumar", function (bool, results) { if (!bool) console.log(results); else { console.log(results); } - });*/ + }); /*dbFile.retrieve_userComments_count("sad@saddy.com", function (bool, result) { - if (!bool) console.log(result); - else { // bool is true i.e no error occured. result contains an integer - console.log(result); - } + if (!bool) console.log(result); + else { // bool is true i.e no error occured. result contains an integer + console.log(result); + } });*/ @@ -153,6 +153,7 @@ var questions_array = ["this is q1", "this is q2"]; console.log(mssg); });*/ +/* dbFile.remove_course("MAT237", function (bool, mssg) { console.log(mssg); -});
\ No newline at end of file +});*/ |
