blob: e93fe2c9d6be0693cb788276507725bb2b2458cc (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
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
})
}
|