Conversation
…ages by amount of likes or amount equal or more than likes, added find by id
…endpoints, added POST
Nicolinabl
left a comment
There was a problem hiding this comment.
Nice work!
Good use of comments and structuring in your code, makes it easier for me to follow along. A next step could have been to split some of the code into different files for better organisation, but i still find it easy to navigate bc of your comments. Tested it with your frontend aswell and as far as i could see it all seems to work. I like that the icons for editing only shows when logged in, nice little extra touch for ui :)
| mongoose.connect(mongoUrl); | ||
| mongoose.Promise = Promise; | ||
|
|
||
| // ---- Models ---- |
There was a problem hiding this comment.
good structuring with comments. Makes it easier to follow along in your code as a reviewer :)
| }); | ||
| } | ||
|
|
||
| if (password.length < 8) { |
There was a problem hiding this comment.
nice extra touch with min length on password
| // ---- Endpoints POST ---- | ||
| // ---- Post a thought: | ||
| app.post("/thoughts", authenticateUser, async (req, res) => { | ||
| //This will only work if next() function is called from the authenticateUser |
| const authenticateUser = async (req, res, next) => { | ||
| const user = await User.findOne; | ||
| const token = req.header("Authorization"); | ||
| if (!token) { | ||
| return res.status(401).json({ message: "User is logged out" }); | ||
| } | ||
|
|
||
| if (user) { | ||
| req.user = user; | ||
| next(); | ||
| } else { | ||
| //user is matched and not authorized to do smth | ||
| res.status(401).json({ loggedOut: true }); | ||
| } | ||
| }; |
There was a problem hiding this comment.
try catch error handling would have been good here
| // ---- / Models ---- | ||
|
|
||
| // Start defining your routes here | ||
| // ---- Authentication function: only authorised users can add or like thoughts |
There was a problem hiding this comment.
a nice touch could have been to separate models, middleware and routes into separate files so it would be easier to maintain and look through.
| }); | ||
|
|
||
| // ---- Like a thought | ||
| app.post("/thoughts/:id/like", async (req, res) => { |
There was a problem hiding this comment.
Minor suggestion: using patch instead of post here.
"patch is typically used to update part of an existing resource" (e.g., incrementing hearts on a thought).
post still works though so im not sure it matters :)
https://get-thoughts-out-api.onrender.com