Add filter and find by account function to contributors #42
@ -34,6 +34,30 @@ class Contributor extends Base {
|
||||
});
|
||||
}
|
||||
|
||||
filterByAccount(search) {
|
||||
return this._byAccount(search, 'filter');
|
||||
}
|
||||
|
||||
findByAccount(search) {
|
||||
return this._byAccount(search, 'find');
|
||||
}
|
||||
|
||||
_byAccount(search, method = 'filter') {
|
||||
|
||||
return this.all().then((contributors) => {
|
||||
const searchEntries = Object.entries(search);
|
||||
|
||||
return contributors[method]((contributor) => {
|
||||
if (!contributor.accounts) { return false; }
|
||||
return contributor.accounts.find((account) => {
|
||||
return searchEntries.every((item) => {
|
||||
let [ key, value ] = item;
|
||||
return account[key] === value;
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
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 😀