From 5970b8e5bbf993c88c1f901708a7c5075a916770 Mon Sep 17 00:00:00 2001 From: vantezzen Date: Fri, 23 Aug 2019 14:04:22 +0200 Subject: Add support for workspaces --- app/Controllers/Http/RecipeController.js | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 app/Controllers/Http/RecipeController.js (limited to 'app/Controllers/Http/RecipeController.js') 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 @@ +'use strict' + +const Recipe = use('App/Models/Recipe'); +const fetch = require('node-fetch'); + +class RecipeController { + async list({ + response + }) { + const officialRecipes = JSON.parse(await (await fetch('https://api.franzinfra.com/v1/recipes')).text()); + const customRecipesArray = (await Recipe.all()).rows; + const customRecipes = customRecipesArray.map(recipe => ({ + "id": recipe.recipeId, + "name": recipe.name, + ...JSON.parse(recipe.data) + })) + + const recipes = [ + ...officialRecipes, + ...customRecipes, + ] + + return response.send(recipes) + } +} + +module.exports = RecipeController -- cgit v1.2.3-70-g09d2