diff --git a/agents/getters/getMembersByGroup.js b/agents/getters/getMembersByGroup.js index fef8589..09781f8 100644 --- a/agents/getters/getMembersByGroup.js +++ b/agents/getters/getMembersByGroup.js @@ -1,22 +1,17 @@ -const { pipe, toPairs, map, reduce, keys, invertObj } = require('ramda') +const { pipe, toPairs, map, filter, reduce } = require('ramda') const { createSelector } = require('reselect') -const getRelationshipsBySourceTargetType = require('../../relationships/getters/getRelationshipsBySourceTargetType') +const getRolesBySourceTarget = require('../../relationships/getters/getRolesBySourceTarget') module.exports = createSelector( - getRelationshipsBySourceTargetType, - pipe( - map(pipe( - toPairs, - // TODO combine relationships into roles more intellingently - // - check for member relationship, otherwise no roles - // - handle duplicate relationships of same type (how?) - reduce((sofar, [targetId, relationshipsByType]) => { - const agentId = targetId - const roles = map(() => true, relationshipsByType) - const member = { agentId, roles } - return [...sofar, member] - }, []) - )) - ) + getRolesBySourceTarget, + map(pipe( + toPairs, + filter(([targetId, roles]) => roles.member), + reduce((sofar, [targetId, roles]) => { + const agentId = targetId + const member = { agentId, roles } + return [...sofar, member] + }, []) + )) ) diff --git a/relationships/getters/getRolesBySourceTarget.js b/relationships/getters/getRolesBySourceTarget.js new file mode 100644 index 0000000..4f1150b --- /dev/null +++ b/relationships/getters/getRolesBySourceTarget.js @@ -0,0 +1,18 @@ +const { createSelector } = require('reselect') +const { map } = require('ramda') + +const getRelationshipsBySourceTargetType = require('./getRelationshipsBySourceTargetType') + +// TODO combine relationships into roles more intellingently +// - handle duplicate relationships of same type (how?) + +const getRolesBySourceTarget = createSelector( + getRelationshipsBySourceTargetType, + map( // map into source + map( // map into target + map(() => true) // map into relationshipType + ) + ) +) + +module.exports = getRolesBySourceTarget