aboutsummaryrefslogtreecommitdiffstats
path: root/app/Controllers/Http/RecipeController.js
diff options
context:
space:
mode:
Diffstat (limited to 'app/Controllers/Http/RecipeController.js')
-rw-r--r--app/Controllers/Http/RecipeController.js30
1 files changed, 18 insertions, 12 deletions
diff --git a/app/Controllers/Http/RecipeController.js b/app/Controllers/Http/RecipeController.js
index 7109d2d..1905886 100644
--- a/app/Controllers/Http/RecipeController.js
+++ b/app/Controllers/Http/RecipeController.js
@@ -137,21 +137,27 @@ class RecipeController {
137 const needle = request.input('needle'); 137 const needle = request.input('needle');
138 138
139 // Get results 139 // Get results
140 let remoteResults = [];
141 if (Env.get('CONNECT_WITH_FRANZ') == 'true' && needle !== 'ferdi:custom') { // eslint-disable-line eqeqeq
142 remoteResults = JSON.parse(await (await fetch(`https://api.franzinfra.com/v1/recipes/search?needle=${encodeURIComponent(needle)}`)).text());
143 }
144 const localResultsArray = (await Recipe.query().where('name', 'LIKE', `%${needle}%`).fetch()).toJSON();
145 const localResults = localResultsArray.map((recipe) => ({
146 id: recipe.recipeId,
147 name: recipe.name,
148 ...JSON.parse(recipe.data),
149 }));
150
151 let results; 140 let results;
141
152 if (needle === 'ferdi:custom') { 142 if (needle === 'ferdi:custom') {
153 results = localResults; 143 const dbResults = (await Recipe.all().fetch()).toJSON();
144 results = dbResults.map((recipe) => ({
145 id: recipe.recipeId,
146 name: recipe.name,
147 ...JSON.parse(recipe.data),
148 }));
154 } else { 149 } else {
150 let remoteResults = [];
151 if (Env.get('CONNECT_WITH_FRANZ') == 'true') { // eslint-disable-line eqeqeq
152 remoteResults = JSON.parse(await (await fetch(`https://api.franzinfra.com/v1/recipes/search?needle=${encodeURIComponent(needle)}`)).text());
153 }
154 const localResultsArray = (await Recipe.query().where('name', 'LIKE', `%${needle}%`).fetch()).toJSON();
155 const localResults = localResultsArray.map((recipe) => ({
156 id: recipe.recipeId,
157 name: recipe.name,
158 ...JSON.parse(recipe.data),
159 }));
160
155 results = [ 161 results = [
156 ...localResults, 162 ...localResults,
157 ...remoteResults || [], 163 ...remoteResults || [],