summaryrefslogtreecommitdiff
path: root/src/pages/api
diff options
context:
space:
mode:
Diffstat (limited to 'src/pages/api')
-rw-r--r--src/pages/api/shop/brands.js50
1 files changed, 26 insertions, 24 deletions
diff --git a/src/pages/api/shop/brands.js b/src/pages/api/shop/brands.js
index dbbfcfe3..1217aa48 100644
--- a/src/pages/api/shop/brands.js
+++ b/src/pages/api/shop/brands.js
@@ -1,36 +1,38 @@
-import axios from 'axios'
+import axios from 'axios';
+
+const SOLR_HOST = process.env.SOLR_HOST;
export default async function handler(req, res) {
try {
- let params = '*:*'
- let sort = 'sort=if(exists(sequence_i),0,1) asc,sequence_i asc, if(exists(image_s),0,1) asc '
- let rows = 2000
+ let params = '*:*';
+ let sort =
+ 'sort=if(exists(sequence_i),0,1) asc,sequence_i asc, if(exists(image_s),0,1) asc ';
+ let rows = 2000;
if (req.query.params) {
- rows = 100
+ rows = 100;
switch (req?.query?.params) {
case 'level_s':
- params = 'level_s:prioritas'
- break
+ params = 'level_s:prioritas';
+ break;
case 'search':
- params = `name_s:${req?.query?.q.toLowerCase()}`
- sort = ''
- rows = 1
+ params = `name_s:${req?.query?.q.toLowerCase()}`;
+ sort = '';
+ rows = 1;
break;
default:
- params = `name_s:${req.query.params}`
+ params = `name_s:${req.query.params}`.toLowerCase();
}
}
- let brands = await axios(
- process.env.SOLR_HOST +
- `/solr/brands/select?q=${params}&q.op=OR&indent=true&rows=${rows}&${sort}`
- )
- let dataBrands = responseMap(brands.data.response.docs)
+ const url = `${SOLR_HOST}/solr/brands/select?q=${params}&q.op=OR&indent=true&rows=${rows}&${sort}`;
+ console.log(url);
+ let brands = await axios(url);
+ let dataBrands = responseMap(brands.data.response.docs);
- res.status(200).json(dataBrands)
+ res.status(200).json(dataBrands);
} catch (error) {
- console.error('Error fetching data from Solr:', error)
- res.status(500).json({ error: 'Internal Server Error' })
+ console.error('Error fetching data from Solr:', error);
+ res.status(500).json({ error: 'Internal Server Error' });
}
}
@@ -40,9 +42,9 @@ const responseMap = (brands) => {
id: brand.id,
name: brand.display_name_s,
logo: brand.image_s || '',
- sequance: brand.sequence_i || ''
- }
+ sequance: brand.sequence_i || '',
+ };
- return brandMapping
- })
-}
+ return brandMapping;
+ });
+};