-
Notifications
You must be signed in to change notification settings - Fork 195
/
dinnerModel.js
325 lines (309 loc) · 7.97 KB
/
dinnerModel.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
//DinnerModel class
class DinnerModel {
constructor() {
this.dishes = dishesConst;
//TODO Lab 1
// implement the data structure that will hold number of guests
// and selected dishes for the dinner menu
}
setNumberOfGuests(num) {
//TODO Lab 1
}
getNumberOfGuests() {
//TODO Lab 1
}
//Returns the dishes that are on the menu for selected type
getSelectedDishes(type) {
//TODO Lab 1
}
//Returns all the dishes on the menu.
getFullMenu() {
//TODO Lab 1
}
//Returns all ingredients for all the dishes on the menu.
getAllIngredients() {
//TODO Lab 1
}
//Returns the total price of the menu (price per serving of each dish multiplied by number of guests).
getTotalMenuPrice() {
//TODO Lab 1
}
//Adds the passed dish to the menu.
addDishToMenu(dish) {
//TODO Lab 1
}
//Removes dish with specified id from menu
removeDishFromMenu(id) {
//TODO Lab 1
}
//Returns all dishes of specific type (i.e. "starter", "main dish" or "dessert").
//query argument, text, if passed only returns dishes that contain the query in name or one of the ingredients.
//if you don't pass any query, all the dishes will be returned
getAllDishes(type, query) {
return this.dishes.filter(function (dish) {
let found = true;
if (query) {
found = false;
dish.extendedIngredients.forEach(function (ingredient) {
if (ingredient.name.indexOf(query) !== -1) {
found = true;
}
});
if (dish.name.indexOf(query) !== -1) {
found = true;
}
}
return (dish.dishTypes.includes(type) || !type) && found;
});
}
//Returns a dish of specific ID
getDish(id) {
for (let dish of this.dishes) {
if (dish.id === id) {
return dish;
}
}
return undefined;
}
}
// the dishes constant contains an array of all the
// dishes in the database. Each dish has id, name, array of dishTypes,
// image (name of the image file), instructions and
// array of ingredients. Each ingredient has name,
// amount (a number) and unit (string
// defining the unit i.e. "g", "slices", "ml". Unit
// can sometimes be empty like in the example of eggs where
// you just say "5 eggs" and not "5 pieces of eggs" or anything else.
const dishesConst = [{
'id': 1,
'name': 'French toast',
'dishTypes': ['starter', 'breakfast'],
'image': 'toast.jpg',
'instructions': "In a large mixing bowl, beat the eggs. Add the milk, brown sugar and nutmeg; stir well to combine. Soak bread slices in the egg mixture until saturated. Heat a lightly oiled griddle or frying pan over medium high heat. Brown slices on both sides, sprinkle with cinnamon and serve hot.",
'pricePerServing': 32.5,
'extendedIngredients': [{
'name': 'eggs',
'amount': 0.5,
'unit': '',
}, {
'name': 'milk',
'amount': 30,
'unit': 'ml',
}, {
'name': 'brown sugar',
'amount': 7,
'unit': 'g',
}, {
'name': 'ground nutmeg',
'amount': 0.5,
'unit': 'g',
}, {
'name': 'white bread',
'amount': 2,
'unit': 'slices',
}]
}, {
'id': 2,
'name': 'Sourdough Starter',
'dishTypes': ['starter'],
'image': 'sourdough.jpg',
'instructions': "Here is how you make it... Lore ipsum...",
'pricePerServing': 43.2,
'extendedIngredients': [{
'name': 'active dry yeast',
'amount': 0.5,
'unit': 'g',
}, {
'name': 'warm water',
'amount': 30,
'unit': 'ml',
}, {
'name': 'all-purpose flour',
'amount': 15,
'unit': 'g',
}]
}, {
'id': 3,
'name': 'Baked Brie with Peaches',
'dishTypes': ['starter', 'lunch'],
'image': 'bakedbrie.jpg',
'instructions': "Here is how you make it... Lore ipsum...",
'pricePerServing': 52.8,
'extendedIngredients': [{
'name': 'round Brie cheese',
'amount': 10,
'unit': 'g',
}, {
'name': 'raspberry preserves',
'amount': 15,
'unit': 'g',
}, {
'name': 'peaches',
'amount': 1,
'unit': '',
}]
}, {
'id': 100,
'name': 'Meat balls',
'dishTypes': ['main dish'],
'image': 'meatballs.jpg',
'instructions': "Preheat an oven to 400 degrees F (200 degrees C). Place the beef into a mixing bowl, and season with salt, onion, garlic salt, Italian seasoning, oregano, red pepper flakes, hot pepper sauce, and Worcestershire sauce; mix well. Add the milk, Parmesan cheese, and bread crumbs. Mix until evenly blended, then form into 1 1/2-inch meatballs, and place onto a baking sheet. Bake in the preheated oven until no longer pink in the center, 20 to 25 minutes.",
'pricePerServing': 33.5,
'extendedIngredients': [{
'name': 'extra lean ground beef',
'amount': 115,
'unit': 'g',
}, {
'name': 'sea salt',
'amount': 0.7,
'unit': 'g',
}, {
'name': 'small onion, diced',
'amount': 0.25,
'unit': '',
}, {
'name': 'garlic salt',
'amount': 0.7,
'unit': 'g',
}, {
'name': 'Italian seasoning',
'amount': 0.6,
'unit': 'g',
}, {
'name': 'dried oregano',
'amount': 0.3,
'unit': 'g',
}, {
'name': 'crushed red pepper flakes',
'amount': 0.6,
'unit': 'g',
}, {
'name': 'Worcestershire sauce',
'amount': 6,
'unit': 'ml',
}, {
'name': 'milk',
'amount': 20,
'unit': 'ml',
}, {
'name': 'grated Parmesan cheese',
'amount': 5,
'unit': 'g',
}, {
'name': 'seasoned bread crumbs',
'amount': 15,
'unit': 'g',
}]
}, {
'id': 101,
'name': 'MD 2',
'dishTypes': ['main dish'],
'image': 'bakedbrie.jpg',
'instructions': "Here is how you make it... Lore ipsum...",
'pricePerServing': 43.2,
'extendedIngredients': [{
'name': 'ingredient 1',
'amount': 1,
'unit': 'pieces',
}, {
'name': 'ingredient 2',
'amount': 15,
'unit': 'g',
}, {
'name': 'ingredient 3',
'amount': 10,
'unit': 'ml',
}]
}, {
'id': 102,
'name': 'MD 3',
'dishTypes': ['main dish'],
'image': 'meatballs.jpg',
'instructions': "Here is how you make it... Lore ipsum...",
'pricePerServing': 25.2,
'extendedIngredients': [{
'name': 'ingredient 1',
'amount': 2,
'unit': 'pieces',
}, {
'name': 'ingredient 2',
'amount': 10,
'unit': 'g',
}, {
'name': 'ingredient 3',
'amount': 5,
'unit': 'ml',
}]
}, {
'id': 103,
'name': 'MD 4',
'dishTypes': ['main dish'],
'image': 'meatballs.jpg',
'instructions': "Here is how you make it... Lore ipsum...",
'pricePerServing': 52.0,
'extendedIngredients': [{
'name': 'ingredient 1',
'amount': 1,
'unit': 'pieces',
}, {
'name': 'ingredient 2',
'amount': 12,
'unit': 'g',
}, {
'name': 'ingredient 3',
'amount': 6,
'unit': 'ml',
}]
}, {
'id': 200,
'name': 'Chocolat Ice cream',
'dishTypes': ['dessert'],
'image': 'icecream.jpg',
'instructions': "Here is how you make it... Lore ipsum...",
'pricePerServing': 12.2,
'extendedIngredients': [{
'name': 'ice cream',
'amount': 100,
'unit': 'ml',
}]
}, {
'id': 201,
'name': 'Vanilla Ice cream',
'dishTypes': ['dessert'],
'image': 'icecream.jpg',
'instructions': "Here is how you make it... Lore ipsum...",
'pricePerServing': 21.2,
'extendedIngredients': [{
'name': 'ice cream',
'amount': 100,
'unit': 'ml',
}]
}, {
'id': 202,
'name': 'Strawberry',
'dishTypes': ['dessert'],
'image': 'icecream.jpg',
'instructions': "Here is how you make it... Lore ipsum...",
'pricePerServing': 15.0,
'extendedIngredients': [{
'name': 'ice cream',
'amount': 100,
'unit': 'ml',
}]
}
];
// Deepfreeze, you can ignore this function
// https://github.com/substack/deep-freeze/blob/master/index.js
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/freeze
function deepFreeze(o) {
Object.freeze(o);
Object.getOwnPropertyNames(o).forEach(function (prop) {
if (o.hasOwnProperty(prop)
&& o[prop] !== null
&& (typeof o[prop] === "object" || typeof o[prop] === "function")
&& !Object.isFrozen(o[prop])) {
deepFreeze(o[prop]);
}
});
}
deepFreeze(dishesConst);