blob: af3525b30f12c6cac59ecb45805246cc15ef5c63 (
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
|
import { productMappingSolr, variantsMappingSolr } from '@/utils/solrMapping';
import axios from 'axios';
export default async function handler(req, res) {
try {
let productVariants = await axios(
process.env.SOLR_HOST +
`/solr/variants/select?q=id:${req.query.id}&q.op=OR&indent=true`
);
let template_id = productVariants.data.response.docs[0].template_id_i;
let auth =
req.query.auth === 'false' ? JSON.parse(req.query.auth) : req.query.auth;
let productTemplate = await axios(
process.env.SOLR_HOST +
`/solr/product/select?q=id:${template_id}&q.op=OR&indent=true`
);
let result = variantsMappingSolr(
productTemplate.data.response.docs,
productVariants.data.response.docs,
auth || false
);
res.status(200).json(result);
} catch (error) {
console.error('Error fetching data from Solr:', error);
res.status(500).json({ error: 'Internal Server Error' });
}
}
|