diff --git a/queryMaker.js b/queryMaker.js index 32c1128..625b173 100644 --- a/queryMaker.js +++ b/queryMaker.js @@ -108,5 +108,10 @@ module.exports = { } ] } + }, + + userListQuery: function (params) { + console.log(params.query.usertype) + return {"Type" : params.query.usertype}, {"_id": 1, "UserName": 1} } } \ No newline at end of file diff --git a/server.js b/server.js index 65d257c..39ac407 100644 --- a/server.js +++ b/server.js @@ -109,6 +109,34 @@ router.get('/details', function (req, res) { } }); +router.get('/user-list', function (req, res) { + var paramValid = utility.userListParamChecker(req); + console.log(paramValid); + if (!paramValid.valid) { + res.json({ error : paramValid.msg }); + } else { + var report = []; + MongoClient.connect(url, function (err, db) { + assert.equal(null, err); + var query = queryMaker.userListQuery(req); + console.log({"Type" : req.query.usertype}, {"_id": 1, "UserName": 1}); + var userList = db.collection('Users').find({"Type" : req.query.usertype}, {"_id": 1, "UserName": 1}).toArray(function (err, result) { + console.log(result.length) + if (err) { + console.log(err); + } else if (result.length) { + res.json({ data: result }) + } else { + res.json({ error: "No document(s) found with defined find criteria!" }) + } + //Close connection + db.close(); + }); + + }) + } +}) + router.post('/product', function (req, res) { console.log(req.body); var product = req.body; diff --git a/utility.js b/utility.js index 70ab0ff..3123ad8 100644 --- a/utility.js +++ b/utility.js @@ -44,6 +44,16 @@ module.exports = { else return {valid: true}; }, + userListParamChecker: function (params) { + if (!params.query.usertype) { + return { valid : false, msg: "usertype is not available" } + } + else if (!params.query.usertype === "ENTERPRISE" || !params.query.type === "BIKE_MESSENGER") { + return { valid : false, msg: "usertype must be ENTERPRISE or BIKE_MESSENGER" } + } + return { valid : true } + }, + getProductNames : function (PackageList) { var packages = PackageList.map(function (package) { return "Name: " + package.Item +