From 99c4cb57bf5f2a385ca6571ac02ec3bd6f037b89 Mon Sep 17 00:00:00 2001 From: luandro Date: Tue, 11 Aug 2020 20:06:43 -0300 Subject: [PATCH] application.list: check accepted option type at start and more readable linear filtering logic --- method/application/list.js | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/method/application/list.js b/method/application/list.js index e7208298..b60c2165 100644 --- a/method/application/list.js +++ b/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: { @@ -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)