Skip to content
This repository was archived by the owner on Aug 17, 2024. It is now read-only.

Conversation

@ShimenAfshar
Copy link

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 repository

Your Details

  • Your Name:
  • Your City:
  • Your Slack Name:

Homework Details

  • Module:
  • Week:

Notes

  • What did you find easy?

  • What did you find hard?

  • What do you still not understand?

  • Any other notes?


app.get("/bookings/:id", (request, response) => {
const id = Number(request.params.id);
const findId = bookings.find((bookings) => bookings.id === id);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the find method works well here, nice job


app.post("/bookings", (request, response) => {
if (
request.body.firstName === "" ||
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you could always do some destructuring here to avoid having to type request.body, for example:
const {body} = request

Comment on lines +36 to +44
request.body.email === "" ||
request.body.surname == "" ||
request.body.title === "" ||
request.body.checkInDate === "" ||
request.body.checkOutDate === "" ||
request.body.roomId === null
) {
response.status(400).json({ message: "please fill all the fields" });
return;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this works & 400 makes sense. You could have a think about creating a function to deal with the above (for example the function could take an array of required fields & the request body and return true/false depending on if all required fields are present )

roomId: request.body.roomId,
checkInDate: request.body.checkInDate,
checkOutDate: request.body.checkOutDate,
};
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

new bookings are posted successfully, well done

Comment on lines +63 to +66
if (requestId < 0) {
return response.status(404).json({ msg: "message not found" });

}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this isn't working as expected at the moment - if I put in an id that doesn't exist (that is larger or equal to 0) I don't get the 404 - have a think what array method could be used here to check if the id exists in the bookings array.
Also really good that you're filtering the bookings so you end up with an array without the given id, but at the moment you're just sending the new array back in the response, remember to actually update the bookings array :)

Copy link

@Nomes27 Nomes27 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just a quick note on node_modules, make sure you add a .gitignore file and add node_modules to this, so that they don't get committed :)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants