From bf35c7be0db5b9b022a00c638ff98a231a644799 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miko=20Keskim=C3=A4ki?= Date: Mon, 6 Mar 2023 11:30:59 +0200 Subject: [PATCH] Api to fetch all iam groups --- src/index.js | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/src/index.js b/src/index.js index 632cbe7..34470f8 100644 --- a/src/index.js +++ b/src/index.js @@ -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) => { @@ -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)