Making the Purchase
You call the makePurchase() function, shown in Listing 28.28, when a user clicks the Make Purchase button in the billing view. This method sends an $http POST method to the /orders/add route on the server. The POST request contains orderBilling, orderShipping, and orderItems parameters. If the request is successful, the $scope.customer.cart is initialized to [] to match the empty array value that will be set in the customer document in MongoDB.
Also, if the request is successful, a new order document will have been created in the MongoDB database. Therefore, you make another $http request, this time to /orders/get, to get the full list of orders, including the new one. Then the view switches to orders.html.
Listing 28.28
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access