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 2e8d00bc2c - Show all commits

View File

@ -34,6 +34,21 @@ class Contributor extends Base {
});
}
filterByAccount(search) {
return this.all().then((contributors) => {
const searchEntries = Object.entries(search);
return contributors.filter((contributor) => {
if (!contributor.accounts) { return false; }
return contributor.accounts.find((account) => {
return searchEntries.reduce((accumulator, searchValue) => {
return accumulator && account[searchValue[0]] === searchValue[1];
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 😀
}, true);
});
});
});
}
add(contributorAttr, callOptions = {}) {
let json = ContributorSerializer.serialize(contributorAttr);
// TODO: validate against schema