productos, equivalencias, cross-sell y cantidades

This commit is contained in:
Lucas Tettamanti
2026-01-18 18:28:28 -03:00
parent 8cc4744c49
commit c7c56ddbfc
32 changed files with 4083 additions and 2073 deletions

View File

@@ -1,19 +1,64 @@
import { listAliases, insertAlias, updateAlias, deleteAlias } from "../db/repo.js";
import {
listAliases,
insertAlias,
updateAlias,
deleteAlias,
listAliasMappings,
setAliasMappings,
} from "../db/repo.js";
export async function handleListAliases({ tenantId, q = "", woo_product_id = null, limit = 200 }) {
const items = await listAliases({ tenantId, q, woo_product_id, limit });
return { items };
}
export async function handleCreateAlias({ tenantId, alias, woo_product_id, boost = 0, category_hint = null, metadata = {} }) {
return insertAlias({ tenantId, alias, woo_product_id, boost, category_hint, metadata });
export async function handleCreateAlias({
tenantId,
alias,
woo_product_id,
boost = 0,
category_hint = null,
metadata = {},
product_mappings = [],
}) {
const result = await insertAlias({ tenantId, alias, woo_product_id, boost, category_hint, metadata });
// Si hay mappings, guardarlos
if (product_mappings && product_mappings.length > 0) {
await setAliasMappings({ tenantId, alias, mappings: product_mappings });
} else if (woo_product_id) {
// Si solo hay un producto, crear mapping por defecto
await setAliasMappings({ tenantId, alias, mappings: [{ woo_product_id, score: boost || 1.0 }] });
}
return result;
}
export async function handleUpdateAlias({ tenantId, alias, woo_product_id, boost = 0, category_hint = null, metadata = {} }) {
return updateAlias({ tenantId, alias, woo_product_id, boost, category_hint, metadata });
export async function handleUpdateAlias({
tenantId,
alias,
woo_product_id,
boost = 0,
category_hint = null,
metadata = {},
product_mappings,
}) {
const result = await updateAlias({ tenantId, alias, woo_product_id, boost, category_hint, metadata });
// Si hay mappings, actualizarlos
if (product_mappings !== undefined) {
await setAliasMappings({ tenantId, alias, mappings: product_mappings || [] });
}
return result;
}
export async function handleDeleteAlias({ tenantId, alias }) {
const deleted = await deleteAlias({ tenantId, alias });
return { deleted };
}
export async function handleGetAliasMappings({ tenantId, alias }) {
const mappings = await listAliasMappings({ tenantId, alias });
return { mappings };
}

View File

@@ -0,0 +1,23 @@
import {
listProductQtyRules,
getProductQtyRules,
saveProductQtyRules,
countQtyRulesByProduct,
} from "../db/repo.js";
export async function handleListProductQtyRules({ tenantId }) {
const rules = await listProductQtyRules({ tenantId });
const counts = await countQtyRulesByProduct({ tenantId });
return { rules, counts };
}
export async function handleGetProductQtyRules({ tenantId, wooProductId }) {
const rules = await getProductQtyRules({ tenantId, wooProductId });
return { rules };
}
export async function handleSaveProductQtyRules({ tenantId, wooProductId, rules }) {
await saveProductQtyRules({ tenantId, wooProductId, rules });
const updated = await getProductQtyRules({ tenantId, wooProductId });
return { rules: updated };
}

View File

@@ -26,8 +26,14 @@ export async function handleCreateRecommendation({
priority = 100,
trigger_product_ids = [],
recommended_product_ids = [],
rule_type = "crosssell",
trigger_event = null,
items = [],
}) {
return insertRecommendation({ tenantId, rule_key, trigger, queries, boosts, ask_slots, active, priority, trigger_product_ids, recommended_product_ids });
return insertRecommendation({
tenantId, rule_key, trigger, queries, boosts, ask_slots, active, priority,
trigger_product_ids, recommended_product_ids, rule_type, trigger_event, items
});
}
export async function handleUpdateRecommendation({
@@ -41,8 +47,14 @@ export async function handleUpdateRecommendation({
priority,
trigger_product_ids,
recommended_product_ids,
rule_type,
trigger_event,
items,
}) {
return updateRecommendation({ tenantId, id, trigger, queries, boosts, ask_slots, active, priority, trigger_product_ids, recommended_product_ids });
return updateRecommendation({
tenantId, id, trigger, queries, boosts, ask_slots, active, priority,
trigger_product_ids, recommended_product_ids, rule_type, trigger_event, items
});
}
export async function handleDeleteRecommendation({ tenantId, id }) {