Add a filter by account function to contributors
This allows to filter contributors by the account entries. For example: ```js Contributor.filterByAccount({site: 'github.com'}); // returns all contributors with github account Contributor.filterByAccount({site: 'github.com', username: 'bumi'}); // returns bumi ```
This commit is contained in:
parent
1779d66ee6
commit
2e8d00bc2c
@ -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 = {}) {
|
add(contributorAttr, callOptions = {}) {
|
||||||
let json = ContributorSerializer.serialize(contributorAttr);
|
let json = ContributorSerializer.serialize(contributorAttr);
|
||||||
// TODO: validate against schema
|
// TODO: validate against schema
|
||||||
|
Loading…
x
Reference in New Issue
Block a user