Skip to content

Commit

Permalink
Merge pull request #306 from Ohtuilmo/fix/instructor-visible-logs
Browse files Browse the repository at this point in the history
Fetch all groups for both instructors and admin
  • Loading branch information
miahro authored May 3, 2024
2 parents 4ca5705 + 34d1bf9 commit c3cabb7
Showing 1 changed file with 12 additions and 32 deletions.
44 changes: 12 additions & 32 deletions backend/controllers/groups.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,38 +28,18 @@ const formatGroup = (dbGroup) => {
}

router.get('/', checkInstructor, async (req, res) => {
if (req.user.admin) {
const groups = await db.Group.findAll({
include: [
{
as: 'students',
model: db.User,
attributes: ['student_number'], // only select the student number
through: { attributes: [] } // don't ignore junction table stuff
}
]
})
const deserialized = groups.map(formatGroup)
res.json(deserialized)
} else {
const latestConfiguration = await db.Configuration.findOne({
order: [['createdAt', 'DESC']]
})

const groups = await db.Group.findAll({
where: { configuration_id: [latestConfiguration.id] },
include: [
{
as: 'students',
model: db.User,
attributes: ['student_number'], // only select the student number
through: { attributes: [] } // don't ignore junction table stuff
}
]
})
const deserialized = groups.map(formatGroup)
res.json(deserialized)
}
const groups = await db.Group.findAll({
include: [
{
as: 'students',
model: db.User,
attributes: ['student_number'], // only select the student number
through: { attributes: [] } // don't ignore junction table stuff
}
]
})
const deserialized = groups.map(formatGroup)
res.json(deserialized)
})

const isNil = (obj) => obj === null || obj === undefined
Expand Down

0 comments on commit c3cabb7

Please sign in to comment.