Skip to content

Commit

Permalink
user-list api added
Browse files Browse the repository at this point in the history
  • Loading branch information
tareq89 committed Nov 17, 2016
1 parent dba840f commit eee7a9c
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 0 deletions.
5 changes: 5 additions & 0 deletions queryMaker.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,5 +108,10 @@ module.exports = {
}
]
}
},

userListQuery: function (params) {
console.log(params.query.usertype)
return {"Type" : params.query.usertype}, {"_id": 1, "UserName": 1}
}
}
28 changes: 28 additions & 0 deletions server.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
10 changes: 10 additions & 0 deletions utility.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 +
Expand Down

0 comments on commit eee7a9c

Please sign in to comment.