WIP still working on books route#11
Open
oieeri26 wants to merge 9 commits intopce-uw-jscript400:masterfrom
Open
WIP still working on books route#11oieeri26 wants to merge 9 commits intopce-uw-jscript400:masterfrom
oieeri26 wants to merge 9 commits intopce-uw-jscript400:masterfrom
Conversation
bwreid
reviewed
Aug 11, 2019
Collaborator
bwreid
left a comment
There was a problem hiding this comment.
This is really well done, Erik!
| const user = await User.findOne({ | ||
| username | ||
| }) | ||
| if (user) throw new Error(`Username ${username} already taken.`) |
Collaborator
There was a problem hiding this comment.
You might move the above few lines below your validation for username and password. That way, if the username is not long enough, you will throw an error earlier. Right now, you'll make an unnecessary call to the database if that's the case.
| } | ||
| if (!book) throw new Error(`Request body failed: ${JSON.stringify(req.body)}`) | ||
|
|
||
| if (token && checkAdmin.admin) { |
Collaborator
There was a problem hiding this comment.
At this point, I think you just need checkAdmin.admin.
| if (!payload) { | ||
| const error = new Error(`A valid JWT token is not provided.`) | ||
| error.status = 401 | ||
| next(error) |
Collaborator
There was a problem hiding this comment.
I would add return statements next to these next() calls.
| const users = await User.create([ | ||
| { | ||
| username: "user", | ||
| password: "$2b$10$uudM8Q/k8qXrsW99Puwj.evV.0maEhkh2f68/RYcCLdmmmyy7SANS" |
Collaborator
There was a problem hiding this comment.
You could just include bcrypt in this file, and then do bcrypt.hashSync() or the equivalent.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.