diff options
| author | HATEC\SPVDEV001 <tri.susilo@altama.co.id> | 2023-09-25 16:48:25 +0700 |
|---|---|---|
| committer | HATEC\SPVDEV001 <tri.susilo@altama.co.id> | 2023-09-25 16:48:25 +0700 |
| commit | 065a0e341cc42443fe5e2380e078983b3c66f111 (patch) | |
| tree | ee778d9ca0c4c97dc7bb943e6d788814da11949f /src/pages/api/shop | |
| parent | 4d329fbe4ecadd7864809f340d9e4f46d910e418 (diff) | |
migrasi get brand di homepage dan page all brand ke solr
Diffstat (limited to 'src/pages/api/shop')
| -rw-r--r-- | src/pages/api/shop/brands.js | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/src/pages/api/shop/brands.js b/src/pages/api/shop/brands.js new file mode 100644 index 00000000..e4619d15 --- /dev/null +++ b/src/pages/api/shop/brands.js @@ -0,0 +1,44 @@ +import axios from 'axios' + +export default async function handler(req, res) { + try { + let params = '*:*' + let sort = 'sort=if(exists(sequence_i),0,1) asc,sequence_i asc' + let rows = 2000 + + if (req.query.params) { + rows = 100 + switch (req?.query?.params) { + case 'level_s': + params = 'level_s:prioritas' + break + default: + params = `name_s:${req.query.params}` + } + } + 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) + + res.status(200).json(dataBrands) + } catch (error) { + console.error('Error fetching data from Solr:', error) + res.status(500).json({ error: 'Internal Server Error' }) + } +} + +const responseMap = (brands) => { + return brands.map((brand) => { + let brandMapping = { + id: brand.id, + name: brand.display_name_s, + logo: brand.image_s || '', + sequance: brand.sequence_i || '' + } + + return brandMapping + }) +} |
