summaryrefslogtreecommitdiff
path: root/src/api/promoApi.js
diff options
context:
space:
mode:
Diffstat (limited to 'src/api/promoApi.js')
-rw-r--r--src/api/promoApi.js43
1 files changed, 43 insertions, 0 deletions
diff --git a/src/api/promoApi.js b/src/api/promoApi.js
index a4acc768..535df021 100644
--- a/src/api/promoApi.js
+++ b/src/api/promoApi.js
@@ -1,5 +1,6 @@
// src/api/promoApi.js
import odooApi from '@/core/api/odooApi';
+// import { SolrResponse } from "../../../../src-migrate/types/solr.ts";
export const fetchPromoItems = async (type) => {
try {
@@ -10,3 +11,45 @@ export const fetchPromoItems = async (type) => {
return [];
}
};
+
+export const fetchPromoItemsSolr = async (type) => {
+ let start = 0
+ let rows = 120
+ try {
+ const queryParams = new URLSearchParams({ q: `type_value_s:${type}` });
+ const response = await fetch(`/solr/promotion_program_lines/select?${queryParams.toString()}&rows=${rows}&start=${start}`);
+ if (!response.ok) {
+ throw new Error(`HTTP error! status: ${response.status}`);
+ }
+ const data = await response.json();
+ const promotions = await map(data.response.docs);
+ return promotions;
+ } 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,
+ program_id: promotion.program_id_i,
+ name: promotion.name_s,
+ type: {
+ value: promotion.type_value_s,
+ label: promotion.type_label_s,
+ },
+ limit: promotion.package_limit_i,
+ limit_user: promotion.package_limit_user_i,
+ limit_trx: promotion.package_limit_trx_i,
+ price: promotion.price_f,
+ total_qty: promotion.total_qty_i,
+ products: JSON.parse(promotion.products_s),
+ free_products: JSON.parse(promotion.free_products_s),
+ };
+ result.push(data);
+ }
+ return result;
+}; \ No newline at end of file