diff options
| author | trisusilo48 <tri.susilo@altama.co.id> | 2024-07-10 15:58:51 +0700 |
|---|---|---|
| committer | trisusilo48 <tri.susilo@altama.co.id> | 2024-07-10 15:58:51 +0700 |
| commit | 2e3c726bc8217f3960cfecec44b81303b03de72b (patch) | |
| tree | 1b85ced7f61f3e4c3f1f27b577b37aa161615065 /src/pages/api/shop/brands.js | |
| parent | 2b3bd9c0a454dbad69ce29cee877bfb1fca5dfa6 (diff) | |
| parent | a99bf6480eea556e53b85e6db45f3b8c2361e693 (diff) | |
Merge branch 'release' into development
# Conflicts:
# src/pages/shop/product/variant/[slug].jsx
Diffstat (limited to 'src/pages/api/shop/brands.js')
| -rw-r--r-- | src/pages/api/shop/brands.js | 49 |
1 files changed, 25 insertions, 24 deletions
diff --git a/src/pages/api/shop/brands.js b/src/pages/api/shop/brands.js index dbbfcfe3..cc64a7e7 100644 --- a/src/pages/api/shop/brands.js +++ b/src/pages/api/shop/brands.js @@ -1,36 +1,37 @@ -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}`; + 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 +41,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; + }); +}; |
