Add filter and find by account function to contributors #42
@ -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];
|
||||
|
|
||||
}, true);
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
add(contributorAttr, callOptions = {}) {
|
||||
let json = ContributorSerializer.serialize(contributorAttr);
|
||||
// TODO: validate against schema
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user
That's a master piece of functional programming 😀