Skip to content
This repository has been archived by the owner on Jun 16, 2018. It is now read-only.

Commit

Permalink
Added REST service to get published scores by round
Browse files Browse the repository at this point in the history
  • Loading branch information
rikkertkoppes committed Jan 31, 2015
1 parent 1107b3f commit 0f1021d
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions localserver.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,35 @@ app.get('/challenge/:year', function(req, res) {
});
});

//get scores by round
app.get('/scores/:round',function(req,res) {
var path = __dirname + '/data/scores.json';
var round = parseInt(req.params.round,10);
fs.stat(path, function(err, stat) {
if (err) {
res.status(404).send('file not found');
return;
}
if (stat.isFile()) {
fs.readFile(path, function(err, data) {
if (err) {
res.status(500).send('error reading file');
return;
}
var result = JSON.parse(data);
var scores = result.scores;
console.log(round);
var scoresForRound = scores.filter(function(score) {
return score.published && score.round === round;
});
res.json(scoresForRound);
});
} else {
res.status(500).send('error reading file');
return;
}
});
});

function writeFile(path, contents, cb) {
var dir = dirname(path);
Expand Down

0 comments on commit 0f1021d

Please sign in to comment.