Add filter and find by account function to contributors #42

Merged
bumi merged 3 commits from feature/filter-contributors-by-account into master 2018-04-26 14:27:26 +00:00
Showing only changes of commit fe1fa2e881 - Show all commits

View File

@ -35,10 +35,18 @@ class Contributor extends Base {
}
filterByAccount(search) {
return this._byAccount(search, 'filter');
}
findByAccount(search) {
return this._byAccount(search, 'find');
}
_byAccount(search, method = 'filter') {
fsmanuel commented 2018-04-26 13:22:15 +00:00 (Migrated from github.com)
Review

That's a master piece of functional programming 😀

That's a master piece of functional programming 😀
return this.all().then((contributors) => {
const searchEntries = Object.entries(search);
return contributors.filter((contributor) => {
return contributors[method]((contributor) => {
if (!contributor.accounts) { return false; }
return contributor.accounts.find((account) => {
return searchEntries.reduce((accumulator, searchValue) => {