mejoras en el modelo de clarificacion de productos

This commit is contained in:
Lucas Tettamanti
2026-01-17 06:31:49 -03:00
parent 63b9ecef61
commit 204403560e
24 changed files with 1940 additions and 873 deletions

View File

@@ -565,7 +565,8 @@ export async function searchProductAliases({ tenant_id, q = "", limit = 20 }) {
export async function getRecoRules({ tenant_id }) {
const sql = `
select id, tenant_id, rule_key, trigger, queries, boosts, ask_slots, active, priority, created_at, updated_at
select id, tenant_id, rule_key, trigger, queries, boosts, ask_slots, active, priority,
trigger_product_ids, recommended_product_ids, created_at, updated_at
from product_reco_rules
where tenant_id=$1 and active=true
order by priority asc, id asc
@@ -574,9 +575,26 @@ export async function getRecoRules({ tenant_id }) {
return rows;
}
/**
* Buscar reglas que tengan alguno de los productos como trigger.
*/
export async function getRecoRulesByProductIds({ tenant_id, product_ids = [] }) {
if (!product_ids?.length) return [];
const sql = `
select id, tenant_id, rule_key, trigger, queries, boosts, ask_slots, active, priority,
trigger_product_ids, recommended_product_ids, created_at, updated_at
from product_reco_rules
where tenant_id=$1 and active=true and trigger_product_ids && $2::int[]
order by priority asc, id asc
`;
const { rows } = await pool.query(sql, [tenant_id, product_ids]);
return rows;
}
export async function getRecoRuleByKey({ tenant_id, rule_key }) {
const sql = `
select id, tenant_id, rule_key, trigger, queries, boosts, ask_slots, active, priority, created_at, updated_at
select id, tenant_id, rule_key, trigger, queries, boosts, ask_slots, active, priority,
trigger_product_ids, recommended_product_ids, created_at, updated_at
from product_reco_rules
where tenant_id=$1 and rule_key=$2
limit 1