-
-
Notifications
You must be signed in to change notification settings - Fork 445
London9 - Ying Xing - Node - Coursework - Week2 #268
base: master
Are you sure you want to change the base?
Conversation
server.js
Outdated
res.json(findId); | ||
console.log(findId); | ||
} else { | ||
res.status(404).send("Message not found"); |
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 use of status message
server.js
Outdated
app.get("/messages/:id", function(req, res) { | ||
const messageId = req.params.id; | ||
const findId = messages.find((message) => { return message.id === Number(messageId) }); | ||
if (findId) { |
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.
Tiny formatting error where "if" isn't lined up with const but don't worry about that for now!
|
||
console.log(newMessage); | ||
messages.push(newMessage); | ||
res.status(201).json({ success: true, data: messages }); |
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.
Looks good to me!
if (findIndex === -1) { | ||
res.status(404).send("Message not found"); | ||
} else { | ||
messages.splice(findIndex, 1); |
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.
Nice! Looks good!
app.post("/messages", function (req, res) { | ||
const {from, text} = req.body | ||
const newMessage = { | ||
id: messages.length, |
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.
When setting the ID this way, what would happen if you add 3 messages, deleted the first one, then tried to add another?
ie messages = [1, 2, 3] then remove one -> [2, 3] then try to add a new one -> [2, 3, ?]
Volunteers: Are you marking this coursework? You can find a guide on how to mark this coursework in
HOW_TO_MARK.md
in the root of this repositoryYour Details
Homework Details
Notes
What did you find easy?
What did you find hard?
What do you still not understand?
Any other notes?