- Build a domain model with class relations using JavaScript iterator methods
- Use JavaScript to answer questions about data stored in our application
- In this lab, we're using a global store variable to manage application state; it's our frontend 'database'.
In this lab, we will be creating a meal delivery service.
- A meal has many customers
- A delivery belongs to a meal, belongs to a customer, and belongs to a neighborhood
- A customer has many deliveries
- A customer has many meals through deliveries
- A customer belongs to a neighborhood
- A neighborhood has many deliveries
- A neighborhood has many customers through deliveries
- A neighborhood has many meals through deliveries
Please note: the tests do not check these methods in order. Some of these methods rely on the relationships between classes to be working already. Use the tests as a guide and refer to this reading if you need more information about what a method is supposed to be doing.
You will be modeling the following:
new Neighborhood()
- initialized withname
. It returns an object that has attributes ofid
andname
deliveries()
- returns a list of all deliveries placed in a neighborhoodcustomers()
- returns all of the customers that live in a particular neighborhoodmeals()
- returns a unique list of meals that have been ordered in a particular neighborhood (you might want to do this one last)
new Customer()
— should expect to be initialized with a name and a neighborhoodId. It returns an object that has attributes ofid
,neighborhoodId
, andname
.deliveries()
— returns all of the deliveries that customer has receivedmeals()
- returns all meals that a customer has orderedtotalSpent()
- returns the total amount that the customer has spent on food.
new Meal()
— initialized withtitle
andprice
. It returns an object that has attributes oftitle
,price
, andid
. Meal Ids should automatically increment.deliveries()
- returns all of the deliveries associated with a particular meal.customers()
- returns all of the customers who have had the meal delivered. Be careful not to return the same customer twice if they have ordered this meal multiple times.byPrice()
- A class method that orders all meal instances by their price in descending order. Use thestatic
keyword to write a class method.
new Delivery()
— initialized withmealId
,neighborhoodId
, andcustomerId
. It returns an object that has attributes ofmealId
,neighborhoodId
,customerId
, andid
meal()
- returns the meal associated with a particular deliverycustomer()
- returns the customer associated with a particular deliveryneighborhood()
- returns the neighborhood associated with a particular delivery