-
-
Notifications
You must be signed in to change notification settings - Fork 306
Manchester_NW5-Adiba Belayete_Module-03_Node.js- Week-03 #182
base: master
Are you sure you want to change the base?
Conversation
| const foundId = bookings.some( | ||
| (eachbooking) => eachbooking.id === parseInt(request.params.id) | ||
| ); | ||
| console.log(foundId); | ||
| if (foundId) { | ||
| response | ||
| .status(200) | ||
| .json( | ||
| bookings.filter( | ||
| (eachmessage) => eachmessage.id === parseInt(request.params.id) | ||
| ) | ||
| ); |
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.
.some works, but then you're having to use another array method to get the message further down, you could think about combining these and using something like .find: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/find
| response | ||
| .status(404) | ||
| .json({ | ||
| message: `No bookings with the id of ${request.params.id} is 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.
nice, this works well for if the id is not found
| // to create bookings & level :02 | ||
|
|
||
|
|
||
| app.post("/createNewBookings", (request, response) => { |
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.
remember to use the same route you already have - for example should be able to POST and GET from /bookings rather than creating a new route
| // console.log("hello hahha") | ||
| // response.send(request.body) | ||
| let createNewBookings = { | ||
| id: uuid.v4(), |
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 that you're exploring what packages are out there to help with this!
| }); | ||
| } | ||
|
|
||
| bookings.push(createNewBookings); |
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.
your new booking creation works well, nice job. You could extract the logic above into a function (for example passing in an array of required fields and the request body, returning true/false depending on whether all required fields are present)
|
|
||
| // Delete a booking, specified by an ID | ||
|
|
||
| app.delete("/bookings/delete/:id", (request, response) => { |
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.
no need to include the delete verb within the endpoint (as we can already get this information from the method) , so it should just be app.delete("/bookings/:id" - this way it follows the same pattern as the GET endpoint app.get("/bookings/:id
this article goes over some REST api best practises: https://stackoverflow.blog/2020/03/02/best-practices-for-rest-api-design/
| bookings: bookings.filter( | ||
| (eachmessage) => eachmessage.id !== parseInt(request.params.id) |
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 job - filter works well here to remove the deleted item, but remember to update your bookings array so that on subsequent get requests the item is removed (at the moment the updated array is just getting sent back in the response body)
Nomes27
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.
remember to add node_modules to your .gitignore at the start, noticed you've added them to your .gitignore now which is good, but they've already been committed - if you do some googling there's a way to remove them once committed :)
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?