Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

London9-Mohamed Abdi-Node-Coursework-Week3 #242

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

MohamedAbdi114
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:Mohamed Abdi
  • Your City:London
  • Your Slack Name: Mohamed Abdi

Homework Details

  • Module:Node
  • Week:3

Notes

  • What did you find easy?

  • What did you find hard?

  • What do you still not understand?

  • Any other notes?
    @JDysiewicz

Copy link
Member

@JDysiewicz JDysiewicz left a comment

Choose a reason for hiding this comment

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

Overall looks good. A couple points are to give verbose error messages to sent to the front-end, and also you're missing a .gitignore file which is why this PR has included the node_modules folder. We never want to commit this, because it is generated from the package.json file anyways and adds thousands of unnecessary files to the PR.

});

app.get("/booking/:id", function (req, res) {
const bookingId = +req.params.id;
Copy link
Member

Choose a reason for hiding this comment

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

This is a nice way to convert to an int when you know the incoming value will resemble an int, however when you can't be sure it's nice to have some error checking here (e.g. what if the user went to /booking/abc?)

const bookingId = +req.params.id;
const booking = bookings.find((booking) => booking.id === bookingId);
if (!booking) {
res.status(404).send("404 error");
Copy link
Member

Choose a reason for hiding this comment

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

Nice use of status codes here, however you could be more descriptive with the error you send back. This error will be sent to the front-end, so something like res.status(404).json({"message": "Invalid booking id ${bookingId}"}) might be nicer


app.post("/booking", function (req, res) {
const createBooking = req.body;
createBooking.id = bookings.length + 1;
Copy link
Member

Choose a reason for hiding this comment

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

This will work currently, however you can't rely on the length of an array to give you a unique identifier in real applications; for instance, what if a booking is deleted then recreated? You now have bookingId = 2 referring to different bookings at different times (therefore it is not a good identifier). Also if multiple bookings come in at the same time, you could end up with multiple bookingId = 2 as they will all see the current length of the array could be 1 or something. A uuid is what you're looking for here.

Comment on lines +44 to +56
const valid =
!!title &&
!!firstName &&
!!surname &&
!!email &&
(roomId === 0 || !!roomId) &&
!!checkInDate &&
!!checkOutDate;
if (valid) {
bookings.push(createBooking);
res.json(bookings);
} else {
res.status(400).send("Missing Information");
Copy link
Member

Choose a reason for hiding this comment

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

nice error checking, I like it. You could be more informative with what information is missing though in the response.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants