diff options
| author | trisusilo <tri.susilo@altama.co.id> | 2023-09-26 03:08:32 +0000 |
|---|---|---|
| committer | trisusilo <tri.susilo@altama.co.id> | 2023-09-26 03:08:32 +0000 |
| commit | e0fde9bb4ef9299d78dae82221e6b16294d6c597 (patch) | |
| tree | dc0e45f8bbb2ed74c9df3a5b71c86154bce66648 /src/pages/api | |
| parent | 2471cde6bdfbcc3bbc76f26656fdc79bd1f6bdb1 (diff) | |
| parent | 834b057ecb8eb1af06160b01c623332a35b169fa (diff) | |
Merged in CR/migrasi_brand_homepage&all_brand (pull request #79)
CR/migrasi brand homepage&all brand
Diffstat (limited to 'src/pages/api')
| -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..e93fe2c9 --- /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, if(exists(image_s),0,1) 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 + }) +} |
