-
Notifications
You must be signed in to change notification settings - Fork 8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Sciper checking #206
Sciper checking #206
Changes from 8 commits
739c6ee
73ee34a
db37a3f
1d9b193
6130c1e
800a569
de49ea7
9546052
9d5f713
27358ab
dc1d798
42815f2
de824c2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -216,10 +216,23 @@ app.post('/api/add_role', (req, res) => { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
const { sciper } = req.body; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
const { role } = req.body; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
usersDB.put(sciper, role).catch((error) => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
res.status(500).send('Failed to add role'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
console.log(error); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
}); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
// The sciper has to contain 6 numbers | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
if (sciper < 999999 && sciper > 100000) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
// call https://search-api.epfl.ch/api/ldap?q=228271 if the answer | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
// empty then sciper invalid | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
axios.get(`https://search-api.epfl.ch/api/ldap?q=${sciper}`).then((response) => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
if (response.data.length === 0) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
res.status(400).send('Unknown sciper'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
usersDB.put(sciper, role).catch((error) => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
res.status(500).send('Failed to add role'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
console.log(error); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
}); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
}); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For you information, you can also concatenate promises, by returning a promise from within the body of a This is sometimes more readable, and you can group all the errors in one catch.
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
res.status(400).send('sciper length incorrect'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In general, you can reduce indentation by using guard clauses and making the code more readable.
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
}); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
// This call (only for admins) allow an admin to remove a role to a user. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what if the
get
fails ? it seems you don't catch that case.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes I missed this one, I just added a catch in a new commit