-
-
Notifications
You must be signed in to change notification settings - Fork 306
Manchester NW5-Ahmed Mohamed-Node JS-Week3 #174
base: master
Are you sure you want to change the base?
Conversation
AltomHussain
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.
Great job mate :)
| //Create a new booking | ||
| app.post("/booking", (req, resp) => { | ||
| const newBooking = req.body; | ||
| console.log(newBooking); |
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.
You could have cleared your logs once you are done building.
| newBooking.checkOutDate | ||
| ) { | ||
| bookings.push(newBooking); | ||
| resp.send("New Booking has been added >>"); |
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.
In the response message, you could also return the values from the array to make sure you have updated them.
| app.get("/booking/:id", function (request, response) { | ||
| const bookingID = +request.params.id; | ||
| const fliterBooking = bookings.find((booking) => booking.id === bookingID); | ||
| if (!fliterBooking) { |
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.
I don't think you should use this syntax !fliterBooking in your if statement to validate because it might work when the find function returns a value.
The only time you should use this syntax is when you know your function returns true or false but the find method does not return true or false but it returns a value or undefined so you should use undefined to compare in your if statement I believe.
You can read the "Return Value` on this section about the value that the find function retuns
https://www.w3schools.com/jsref/jsref_find.asp#:~:text=The%20find()%20method%20returns,if%20no%20elements%20are%20found.
|
Oh sorry, one more thing! You shouldn't have pushed your |
Volunteers: Are you marking this coursework? You can find a guide on how to mark this coursework in
HOW_TO_MARK.mdin 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?