Skip to content

Commit

Permalink
feat(getInternalData): allow filtering returned fields
Browse files Browse the repository at this point in the history
Supply `fields` array with names of fields to return
  • Loading branch information
AVVS committed Feb 23, 2016
1 parent 6451ac9 commit 611e3ee
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
3 changes: 2 additions & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
"prefer-arrow-callback": 0,
"max-len": [2, 150],
"newline-per-chained-call": 0,
"no-param-reassign": [2, {"props": false}]
"no-param-reassign": [2, {"props": false}],
"arrow-body-style": 0
},
"root": true
}
9 changes: 9 additions & 0 deletions schemas/getInternalData.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,15 @@
"type": "string",
"minLength": 3,
"maxLength": 50
},
"fields": {
"type": "array",
"minItems": 1,
"items": {
"type": "string",
"minLength": 1,
"maxLength": 50
}
}
}
}
8 changes: 7 additions & 1 deletion src/actions/getInternalData.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
const Promise = require('bluebird');
const getInternalData = require('../utils/getInternalData.js');
const pick = require('lodash/pick');

module.exports = function internalData(message) {
const { fields } = message;

return Promise
.bind(this, message.username)
.then(getInternalData);
.then(getInternalData)
.then(data => {
return fields ? pick(data, fields) : data;
});
};

0 comments on commit 611e3ee

Please sign in to comment.