Skip to content

Commit

Permalink
Merge pull request #12 from Agreon/add-no-status-error-handling
Browse files Browse the repository at this point in the history
Add check for existing status of user
  • Loading branch information
katlyn authored Oct 2, 2020
2 parents 28c0e80 + 0c26f1c commit ebcfaf6
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion src/routes/me.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,14 +106,28 @@ router.post('/status', async (req, res) => {
})

router.post('/courses/:id', async (req, res) => {
const member = bot.guilds.get(process.env.CS_GUILD).members.get(req.user.discord.id)

if (member.roles.filter(
role =>
[
process.env.CS_STUDENT,
process.env.CS_ALUMNUS,
process.env.CS_TEACHER
].includes(role)).length === 0
) {
res.status(400)
return res.json({ status: 'User has no status' })
}

const courseExists = await r.exists(`class:${req.params.id}`)
if (courseExists === 0) {
res.status(404)
res.json({ error: 'course not found' })
} else {
await bot.addGuildMemberRole(
process.env.CS_GUILD,
req.user.discord.id,
member.id,
req.params.id,
'Assigning class role'
)
Expand Down

0 comments on commit ebcfaf6

Please sign in to comment.