aboutsummaryrefslogtreecommitdiffstats
path: root/app
diff options
context:
space:
mode:
authorLibravatar vantezzen <properly@protonmail.com>2019-09-06 12:14:27 +0200
committerLibravatar vantezzen <properly@protonmail.com>2019-09-06 12:14:27 +0200
commit4db319476ca5e8dbfcd0ccfc466a7061a2d9ae5b (patch)
treebdcef6e8c8c2cfa4c5752dc8221980f8ae249b17 /app
parentAdd search query for listing custom recipes (diff)
downloadferdium-server-4db319476ca5e8dbfcd0ccfc466a7061a2d9ae5b.tar.gz
ferdium-server-4db319476ca5e8dbfcd0ccfc466a7061a2d9ae5b.tar.zst
ferdium-server-4db319476ca5e8dbfcd0ccfc466a7061a2d9ae5b.zip
Fix recipe search
Diffstat (limited to 'app')
-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 || [],