diff --git a/src/auth/IAMConfig.js b/src/auth/IAMConfig.js index 34d1595..d7d036b 100644 --- a/src/auth/IAMConfig.js +++ b/src/auth/IAMConfig.js @@ -473,7 +473,8 @@ const iamToFaculty = (iam) => { for (const f of faculties) { if (facultyIamsMap[f].includes(iam)) { - return facultyMap[f] + const faculty = data.find(({ code }) => code === facultyMap[f]) + return faculty } } } diff --git a/src/index.js b/src/index.js index 567d7e4..632cbe7 100644 --- a/src/index.js +++ b/src/index.js @@ -91,20 +91,18 @@ app.get('/:id', async (req, res) => { return res.send(user) }) -app.get('/faculty/:id', async (req, res) => { - const { id } = req.params - - const user = await User.findByPk(id) +app.post('/user-organisations', async (req, res) => { + const { userId, iamGroups = [] } = req.body - if (!user) return res.sendStatus(404) + if (userId && iamGroups) User.upsert({ id: userId, iamGroups }) - const faculties = [] - user.iamGroups.forEach((iam) => { - const facultyCode = iamToFaculty(iam) - if (facultyCode) faculties.push(facultyCode) + const faculties = {} + iamGroups.forEach((iam) => { + const faculty = iamToFaculty(iam) + if (faculty) faculties[faculty.code] = faculty }) - return res.send(faculties) + return res.send(Object.values(faculties)) }) app.use(Sentry.Handlers.errorHandler())