diff options
Diffstat (limited to 'app/Controllers/Http/RecipeController.js')
-rw-r--r-- | app/Controllers/Http/RecipeController.js | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/app/Controllers/Http/RecipeController.js b/app/Controllers/Http/RecipeController.js new file mode 100644 index 0000000..0b9d488 --- /dev/null +++ b/app/Controllers/Http/RecipeController.js | |||
@@ -0,0 +1,27 @@ | |||
1 | 'use strict' | ||
2 | |||
3 | const Recipe = use('App/Models/Recipe'); | ||
4 | const fetch = require('node-fetch'); | ||
5 | |||
6 | class RecipeController { | ||
7 | async list({ | ||
8 | response | ||
9 | }) { | ||
10 | const officialRecipes = JSON.parse(await (await fetch('https://api.franzinfra.com/v1/recipes')).text()); | ||
11 | const customRecipesArray = (await Recipe.all()).rows; | ||
12 | const customRecipes = customRecipesArray.map(recipe => ({ | ||
13 | "id": recipe.recipeId, | ||
14 | "name": recipe.name, | ||
15 | ...JSON.parse(recipe.data) | ||
16 | })) | ||
17 | |||
18 | const recipes = [ | ||
19 | ...officialRecipes, | ||
20 | ...customRecipes, | ||
21 | ] | ||
22 | |||
23 | return response.send(recipes) | ||
24 | } | ||
25 | } | ||
26 | |||
27 | module.exports = RecipeController | ||