Implementing the Order Model Controller

Listing 28.10 implements the route handling code for the Order model. There are three routes. The getOrder() route finds a single order, based on the orderId included in the query. The getOrders() route finds all orders that belong to the current user. In this example, userid is hard-coded customerA. If the requests are successful, the order or all of this customer’s orders are returned to the client as JSON strings. If the requests fails, a 404 error is returned.

The addOrder() route handler builds a new Order object by getting the updated-Shipping, updatedBilling, and orderItems parameters from the POST request. If the order saves successfully, the cart field in the Customer object is reset to empty, ...

Get Node.js, MongoDB, and AngularJS Web Development now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.