summaryrefslogtreecommitdiff
path: root/src/lib/home/hooks/useCategoryManagement.js
blob: db4e79e1d38570435d941baa21a25ff13ea5cc6a (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
export const fetchProductManagementSolr = async () => {
  try {
    const queryParams = new URLSearchParams({q: 'type_value_s:bundling'})
    const response = await fetch(`/solr/product_category_management/query?q=*:*&q.op=OR&sort=sequence_i asc&indent=true`);
    // console.log("response", response)
    if (!response.ok) {
      throw new Error(`HTTP error! status: ${response.status}`);
    }
    const data = await response.json();
    // console.log("data",data)
    const dataManagement = await map(data.response.docs);
    // console.log("dataManagement",dataManagement)
    return dataManagement;
  } catch (error) {
    console.error("Error fetching promotion data:", error);
    return [];
  }
};

const map = async (promotions) => {
  const result = [];
  for (const promotion of promotions) {
    const data = {
      id: promotion.id,
      category_id: promotion.category_id_i,
      name: promotion.name_s,
      sequence: promotion.sequence_i,
      image: promotion.image_s,
      category_id2: JSON.parse(promotion.category_id2_s),
    };
    result.push(data);
  }
  return result;
};