-
Notifications
You must be signed in to change notification settings - Fork 0
/
recipe.js
33 lines (32 loc) · 985 Bytes
/
recipe.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
const recipeDB = require('./recipeDB');
const { v4: uuidv4 } = require('uuid');
const recipe = {
getRecipesList: function() {
let allRecipes = [];
for (recpId in recipeDB.recipeDB) {
let recp = {};
recp.title = recipeDB.recipeDB[recpId].title;
recp.id = recpId;
allRecipes.push(recp);
}
return allRecipes;
},
getRecipe: function(recpId) {
let recp = recipeDB.recipeDB[recpId];
if (recp === undefined || recp === null) {
throw "recipe not found";
}
return recp;
},
addRecipe: function(title, author, ingredients, instructions) {
let recipeUid = "recipe-" + uuidv4();
let recp = {};
recp.title = title;
recp.author = author;
recp.ingredients = ingredients;
recp.instructions = instructions;
recipeDB.recipeDB[recipeUid] = recp;
return recipeUid;
}
}
module.exports = recipe;