Skip to content

Commit bf35c7b

Browse files
committed
Api to fetch all iam groups
1 parent dfa9e3b commit bf35c7b

File tree

1 file changed

+17
-7
lines changed

1 file changed

+17
-7
lines changed

src/index.js

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -79,16 +79,14 @@ app.get('/all-access', async (_req, res) => {
7979
return res.send(usersWithAccess)
8080
})
8181

82-
app.get('/:id', async (req, res) => {
83-
const { id } = req.params
84-
85-
const user = await User.findByPk(id)
82+
app.get('/iam-groups', async (_req, res) => {
83+
const users = await User.findAll()
8684

87-
if (!user) return res.sendStatus(404)
85+
const iamGroups = users.map(({ iamGroups }) => iamGroups).flat()
8886

89-
user.iamGroups = user.iamGroups.filter((iam) => relevantIAMs.includes(iam))
87+
const uniqueIamGroups = [...new Set(iamGroups)]
9088

91-
return res.send(user)
89+
return res.send(uniqueIamGroups)
9290
})
9391

9492
app.post('/user-organisations', async (req, res) => {
@@ -105,6 +103,18 @@ app.post('/user-organisations', async (req, res) => {
105103
return res.send(Object.values(faculties))
106104
})
107105

106+
app.get('/:id', async (req, res) => {
107+
const { id } = req.params
108+
109+
const user = await User.findByPk(id)
110+
111+
if (!user) return res.sendStatus(404)
112+
113+
user.iamGroups = user.iamGroups.filter((iam) => relevantIAMs.includes(iam))
114+
115+
return res.send(user)
116+
})
117+
108118
app.use(Sentry.Handlers.errorHandler())
109119
app.use(errorHandler)
110120

0 commit comments

Comments
 (0)