Skip to content

Commit

Permalink
application.list: check accepted option type at start and more readab…
Browse files Browse the repository at this point in the history
…le linear filtering logic
  • Loading branch information
luandro committed Aug 11, 2020
1 parent 66de490 commit 99c4cb5
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions method/application/list.js
@@ -1,10 +1,11 @@
const pull = require('pull-stream')

module.exports = function GroupApplicationList (server) {
return function groupApplicationList (
{ groupId = null, accepted = null },
cb
) {
return function groupApplicationList ({ groupId, accepted }, cb) {
if (typeof accepted !== 'boolean' && typeof accepted !== 'undefined')
throw new Error(
'tribes.application.list expected accepted to be (undefined | true | false)'
)
const queryGroupId = [
{
$filter: {
Expand Down Expand Up @@ -44,11 +45,9 @@ module.exports = function GroupApplicationList (server) {
pull.map(i => i.key),
pull.asyncMap(server.tribes.application.get),
pull.filter(i => {
if (accepted !== null) {
if (accepted === true) {
return i.addMember
} else return !i.addMember
} else return i
if (accepted === undefined) return true
if (accepted === true) return i.addMember && i.addMember.length
if (accepted === false) return !i.addMember || i.addMember.length === 0
}),
pull.collect((err, data) => {
cb(err, data)
Expand Down

0 comments on commit 99c4cb5

Please sign in to comment.