aboutsummaryrefslogtreecommitdiffstats
path: root/app
diff options
context:
space:
mode:
authorLibravatar vantezzen <properly@protonmail.com>2019-09-06 12:12:02 +0200
committerLibravatar vantezzen <properly@protonmail.com>2019-09-06 12:12:02 +0200
commitd7bc95b8d52d4916f88b141ca96f842fc777854c (patch)
tree7389805acd7c44427fc1d54aced5577701539946 /app
parentFix recipe name validation (diff)
downloadferdium-server-d7bc95b8d52d4916f88b141ca96f842fc777854c.tar.gz
ferdium-server-d7bc95b8d52d4916f88b141ca96f842fc777854c.tar.zst
ferdium-server-d7bc95b8d52d4916f88b141ca96f842fc777854c.zip
Add search query for listing custom recipes
Diffstat (limited to 'app')
-rw-r--r--app/Controllers/Http/RecipeController.js15
1 files changed, 10 insertions, 5 deletions
diff --git a/app/Controllers/Http/RecipeController.js b/app/Controllers/Http/RecipeController.js
index 17b35fb..7109d2d 100644
--- a/app/Controllers/Http/RecipeController.js
+++ b/app/Controllers/Http/RecipeController.js
@@ -138,7 +138,7 @@ class RecipeController {
138 138
139 // Get results 139 // Get results
140 let remoteResults = []; 140 let remoteResults = [];
141 if (Env.get('CONNECT_WITH_FRANZ') == 'true') { // eslint-disable-line eqeqeq 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()); 142 remoteResults = JSON.parse(await (await fetch(`https://api.franzinfra.com/v1/recipes/search?needle=${encodeURIComponent(needle)}`)).text());
143 } 143 }
144 const localResultsArray = (await Recipe.query().where('name', 'LIKE', `%${needle}%`).fetch()).toJSON(); 144 const localResultsArray = (await Recipe.query().where('name', 'LIKE', `%${needle}%`).fetch()).toJSON();
@@ -148,10 +148,15 @@ class RecipeController {
148 ...JSON.parse(recipe.data), 148 ...JSON.parse(recipe.data),
149 })); 149 }));
150 150
151 const results = [ 151 let results;
152 ...localResults, 152 if (needle === 'ferdi:custom') {
153 ...remoteResults, 153 results = localResults;
154 ]; 154 } else {
155 results = [
156 ...localResults,
157 ...remoteResults || [],
158 ];
159 }
155 160
156 return response.send(results); 161 return response.send(results);
157 } 162 }