This video is available to students only

Module 13 Summary

This lesson is a summary of the work we've done in Module 13.0.

πŸ“ This module's quiz can be found - here.
πŸ—’οΈ Solutions for this module's quiz can be found - here.

In this module, we've created the capability for users to book listings in our application.

Server Project#

src/graphql/typeDefs.ts#

In the GraphQL API type definitions of our server project, we introduced a new root-level mutation field labeled createBooking.

The createBooking mutation accepts an input that is to have an object type of CreateBookingInput. The input is to contain a series of field values that describe the booking that is to be created, such as the id of the listing being booked, the payment source being made, and the check-in/check-out dates of the booking

src/graphql/resolvers/Booking/index.ts#

We've constructed the resolver function for the createBooking mutation in the bookingResolvers map within the src/graphql/resolvers/Booking/index.ts file. The createBooking() resolver function does a few different things:

  • The utility authorize() function is first called to verify the viewer making the request.

  • The listing document being booked is found from the id argument passed in as input to the mutation.

  • A check is made to verify the viewer making the booking is not the host of the listing.

  • Another check is made to verify the check-out date is not before the check-in date of the booking.

  • The bookingsIndex object of the listing is updated to recognize the new dates that have been booked for the listing.

  • The total price of the booking is determined based on the number of days the listing is being booked.

  • A check is made to verify the host is still connected with Stripe such that they will be able to receive payment.

  • A Stripe charge is conducted to pay the host from the person creating the booking.

  • The "bookings" collection is updated with a new booking document.

  • The income of the user document of the host is updated with the new amount of income earned.

  • The bookings field of the user document of the viewer is updated with the id of the new booking that has been made.

  • The listing document of the listing being booked is updated to have a new bookingsIndex object. The bookings field of the listing document is also updated with the id of the new booking that has been made.

Start a new discussion. All notification go to the author.