Skip to content

Commit

Permalink
Api to fetch all iam groups
Browse files Browse the repository at this point in the history
  • Loading branch information
Keskimaki committed Mar 6, 2023
1 parent dfa9e3b commit bf35c7b
Showing 1 changed file with 17 additions and 7 deletions.
24 changes: 17 additions & 7 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,16 +79,14 @@ app.get('/all-access', async (_req, res) => {
return res.send(usersWithAccess)
})

app.get('/:id', async (req, res) => {
const { id } = req.params

const user = await User.findByPk(id)
app.get('/iam-groups', async (_req, res) => {
const users = await User.findAll()

if (!user) return res.sendStatus(404)
const iamGroups = users.map(({ iamGroups }) => iamGroups).flat()

user.iamGroups = user.iamGroups.filter((iam) => relevantIAMs.includes(iam))
const uniqueIamGroups = [...new Set(iamGroups)]

return res.send(user)
return res.send(uniqueIamGroups)
})

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

app.get('/:id', async (req, res) => {
const { id } = req.params

const user = await User.findByPk(id)

if (!user) return res.sendStatus(404)

user.iamGroups = user.iamGroups.filter((iam) => relevantIAMs.includes(iam))

return res.send(user)
})

app.use(Sentry.Handlers.errorHandler())
app.use(errorHandler)

Expand Down

0 comments on commit bf35c7b

Please sign in to comment.