From 77ebea2574c0a4ab85def71518993739e6d6a136 Mon Sep 17 00:00:00 2001 From: "Timothy Roe, Jr" Date: Mon, 28 Dec 2015 11:27:48 -0800 Subject: [PATCH 1/5] Added a New limiting Factor for Matches in API. --- routes/api.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/routes/api.js b/routes/api.js index 95c97f0..a2167a6 100644 --- a/routes/api.js +++ b/routes/api.js @@ -11,7 +11,7 @@ var uuid = require('node-uuid') module.exports = function(app) { // JSON API app.get('/api/stats/:id', statsShow); - app.get('/api/matches', matches); + app.get('/api/matches/:limit', matches); app.get('/api/player/:id', player); app.get('/api/player/:id/matches', playerMatches); app.get('/api/playersearch', playerSearch); @@ -74,9 +74,13 @@ var statsShow = function(req, res) { }; var matches = function(req, res) { + var limitCount = req.params.limit; + if (limitCount == 0) { + limitCount = 12; //Default Value if one is not specified + } Stats.find({}) .sort({_id:-1}) - .limit(12) + .limit(limitCount) .select('hostname redname bluname redCountry bluCountry isLive') .lean() .exec(function(err, matches) { From 8b76f3b356029b838d43f4d15a757a87ec2f12ae Mon Sep 17 00:00:00 2001 From: "Timothy Roe, Jr" Date: Mon, 28 Dec 2015 11:31:54 -0800 Subject: [PATCH 2/5] Fixed Formatting --- routes/api.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/routes/api.js b/routes/api.js index a2167a6..68b15b9 100644 --- a/routes/api.js +++ b/routes/api.js @@ -74,10 +74,10 @@ var statsShow = function(req, res) { }; var matches = function(req, res) { - var limitCount = req.params.limit; - if (limitCount == 0) { - limitCount = 12; //Default Value if one is not specified - } + var limitCount = req.params.limit; + if (limitCount == 0) { + limitCount = 12; //Default Value if one is not specified + } Stats.find({}) .sort({_id:-1}) .limit(limitCount) From 150164b16944390573695d301f7fad1cafd94a63 Mon Sep 17 00:00:00 2001 From: "Timothy Roe, Jr" Date: Mon, 28 Dec 2015 11:38:35 -0800 Subject: [PATCH 3/5] Updated Logic for limiting --- routes/api.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/routes/api.js b/routes/api.js index 68b15b9..898c4fc 100644 --- a/routes/api.js +++ b/routes/api.js @@ -75,7 +75,7 @@ var statsShow = function(req, res) { var matches = function(req, res) { var limitCount = req.params.limit; - if (limitCount == 0) { + if (limitCount < 1 || limitCount == null || ) { limitCount = 12; //Default Value if one is not specified } Stats.find({}) From a8aa88829ad9cde8d0afb7b830e1b262888b42d5 Mon Sep 17 00:00:00 2001 From: "Timothy Roe, Jr" Date: Mon, 28 Dec 2015 11:41:33 -0800 Subject: [PATCH 4/5] Updated Logic for limiting --- routes/api.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/routes/api.js b/routes/api.js index 898c4fc..1662fc3 100644 --- a/routes/api.js +++ b/routes/api.js @@ -75,7 +75,7 @@ var statsShow = function(req, res) { var matches = function(req, res) { var limitCount = req.params.limit; - if (limitCount < 1 || limitCount == null || ) { + if (limitCount < 1 || limitCount == null) { limitCount = 12; //Default Value if one is not specified } Stats.find({}) From 18ecbd18125c6b4895bf849e9eb4bd5cccd002ef Mon Sep 17 00:00:00 2001 From: "Timothy Roe, Jr" Date: Tue, 29 Dec 2015 13:05:20 -0800 Subject: [PATCH 5/5] Added a Maximum Number for the limit --- routes/api.js | 1 + 1 file changed, 1 insertion(+) diff --git a/routes/api.js b/routes/api.js index 1662fc3..b0092d0 100644 --- a/routes/api.js +++ b/routes/api.js @@ -78,6 +78,7 @@ var matches = function(req, res) { if (limitCount < 1 || limitCount == null) { limitCount = 12; //Default Value if one is not specified } + limitCount = Math.min(limitCount, 100); //Limits Count to a Maximum of 100 Stats.find({}) .sort({_id:-1}) .limit(limitCount)