-
-
Notifications
You must be signed in to change notification settings - Fork 76
NW6 | Areeb Sattar | Module Servers | Chat server API project | Week 2 #179
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
base: main
Are you sure you want to change the base?
Conversation
|
garydev10
left a comment
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.
The coding is clear and readable. Good job! It can achieve Level 1 after some change.
|
|
||
| app.post("/messages", (req, res) => { | ||
| const newMessage = req.body; | ||
| messages.push(newMessage); |
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.
Good grasp of Create (POST) function!
However, does reg.body contain all properties required in the message? (See Data Model)
| app.get("/messages/:id", (req, res) => { | ||
| const messageId = parseInt(req.params.id); | ||
| const message = messages.find((obj) => obj.id === messageId ); | ||
| if (!message) return res.status(404).json({ message: "Message does not exist" }); |
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.
Even though your code here is correct and works, a lot of programmers will always add {}s around if bodies, even if they're just one statement - have a read of https://www.synopsys.com/blogs/software-security/understanding-apple-goto-fail-vulnerability-2.html for some explanation as to why :)
|
|
||
| app.delete("/messages/:id", (req, res) => { | ||
| const index = messages.findIndex((obj) => obj.id === parseInt(req.params.id)); | ||
| if (index === -1) return res.status(404).json({ message: "No message to delete" }); |
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.
Even though your code here is correct and works, a lot of programmers will always add {}s around if bodies, even if they're just one statement - have a read of https://www.synopsys.com/blogs/software-security/understanding-apple-goto-fail-vulnerability-2.html for some explanation as to why :)




Learners, PR Template
Self checklist
Changelist
Briefly explain your PR.
Level 1 completed for chat server
Questions
Ask any questions you have for your reviewer.