Skip to content

Commit

Permalink
Allow instructors to see all students and their timelogs
Browse files Browse the repository at this point in the history
  • Loading branch information
vejol committed Aug 7, 2024
1 parent 498cad4 commit 1cf831e
Showing 1 changed file with 1 addition and 24 deletions.
25 changes: 1 addition & 24 deletions backend/controllers/users.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ usersRouter.put('/:studentNumber', checkLogin, async (req, res) => {
// the students in the current configuration, then gets the corresponding
// users from the database.
usersRouter.get('/', checkInstructor, async (req, res) => {
if (req.user.admin) {
if (req.user.admin || req.user.instructor) {
try {
const users = await db.User.findAll()
res.status(200).json(users)
Expand All @@ -47,29 +47,6 @@ usersRouter.get('/', checkInstructor, async (req, res) => {
.status(500)
.json({ error: 'Something is wrong... try reloading the page' })
}
} else {
try {
const configuration = await db.Configuration.findOne({
order: [['createdAt', 'DESC']],
})
const groups = await db.Group.findAll({
where: { configurationId: configuration.id },
include: [{ model: db.User, as: 'students' }],
})
const studentNumbersInGroups = groups
.map((group) => group.students.map((student) => student.student_number))
.flat()

const users = await db.User.findAll({
where: { student_number: studentNumbersInGroups },
})
res.status(200).json(users)
} catch (error) {
console.log(error)
res
.status(500)
.json({ error: 'Something is wrong... try reloading the page' })
}
}
})

Expand Down

0 comments on commit 1cf831e

Please sign in to comment.