NW6 | Areeb Sattar | Module Servers | Chat server API project | Week 2#179
NW6 | Areeb Sattar | Module Servers | Chat server API project | Week 2#179areebsattar wants to merge 2 commits intoCodeYourFuture:mainfrom
Conversation
|
garydev10
left a comment
There was a problem hiding this comment.
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.
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.
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.
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.