Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 12 additions & 17 deletions agents/getters/getMembersByGroup.js
Original file line number Diff line number Diff line change
@@ -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]
}, [])
))
)
18 changes: 18 additions & 0 deletions relationships/getters/getRolesBySourceTarget.js
Original file line number Diff line number Diff line change
@@ -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