Add an exclude parameter to get result in API

This commit is contained in:
Gaël Métais
2015-05-11 16:59:32 +02:00
parent 118ec757a3
commit aba91de480
2 changed files with 117 additions and 0 deletions
+13
View File
@@ -249,6 +249,19 @@ var ApiController = function(app) {
// Retrive one result by id
app.get('/api/results/:id', function(req, res) {
getPartialResults(req.params.id, res, function(data) {
// Some fields can be excluded from the response, this way:
// /api/results/:id?exclude=field1,field2
if (req.query.exclude && typeof req.query.exclude === 'string') {
var excludedFields = req.query.exclude.split(',');
excludedFields.forEach(function(fieldName) {
if (data[fieldName]) {
console.log('excluding ' + fieldName);
delete data[fieldName];
}
});
}
return data;
});
});