Skip to content

Commit

Permalink
Update user faculty api
Browse files Browse the repository at this point in the history
  • Loading branch information
Keskimaki committed Feb 22, 2023
1 parent eae49ec commit dfa9e3b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 11 deletions.
3 changes: 2 additions & 1 deletion src/auth/IAMConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
}
Expand Down
18 changes: 8 additions & 10 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down

0 comments on commit dfa9e3b

Please sign in to comment.