fix
This commit is contained in:
@@ -679,6 +679,14 @@ const (
|
||||
// Prefer processed_* so dashboard product fields match V1 process items for the same EAN.
|
||||
processedPreferredNameSQL = `COALESCE(NULLIF(p.processed_name, ''), NULLIF(p.name, ''), NULLIF(r.mapped_data->>'name', ''), NULLIF(r.mapped_data->>'title', ''), '')`
|
||||
processedPreferredDescriptionSQL = `COALESCE(NULLIF(p.processed_description, ''), NULLIF(p.description, ''), NULLIF(r.mapped_data->>'description', ''), '')`
|
||||
// Pre-enrichment values, with NO processed_* fallback. The preferred SQL above
|
||||
// resolves to the enriched copy whenever it exists, so a review screen that read
|
||||
// "name"/"description" showed the AI output on BOTH sides and every product
|
||||
// looked unchanged. Review must compare against these instead.
|
||||
processedOriginalNameSQL = `COALESCE(NULLIF(p.name, ''), NULLIF(r.mapped_data->>'name', ''), NULLIF(r.mapped_data->>'title', ''), '')`
|
||||
processedOriginalDescriptionSQL = `COALESCE(NULLIF(p.description, ''), NULLIF(r.mapped_data->>'description', ''), '')`
|
||||
// Category the feed supplied (before categorize assigned one).
|
||||
processedFeedCategorySQL = `COALESCE(NULLIF(BTRIM(r.mapped_data->>'category'), ''), NULLIF(BTRIM(r.mapped_data->>'category_unique_id'), ''), '')`
|
||||
processedHasNameSQL = `(` + processedPreferredNameSQL + ` <> '')`
|
||||
processedHasDescriptionSQL = `(` + processedPreferredDescriptionSQL + ` <> '')`
|
||||
processedHasCategorySQL = `(COALESCE(NULLIF(p.category, ''), '') <> '' AND lower(p.category) <> 'none')`
|
||||
@@ -1133,6 +1141,7 @@ func (s *Service) ListProcessedProducts(ctx context.Context, companyID uuid.UUID
|
||||
rows, err := s.Pool.Query(ctx, fmt.Sprintf(`
|
||||
SELECT p.id, p.product_id,
|
||||
`+processedPreferredNameSQL+` AS name,
|
||||
`+processedOriginalNameSQL+` AS original_name,
|
||||
COALESCE(NULLIF(p.processed_name, ''), '') AS processed_name,
|
||||
p.category,
|
||||
cat.name AS category_name,
|
||||
@@ -1161,7 +1170,7 @@ func (s *Service) ListProcessedProducts(ctx context.Context, companyID uuid.UUID
|
||||
}
|
||||
defer rows.Close()
|
||||
items, err := scanMaps(rows, []string{
|
||||
"id", "product_id", "name", "processed_name", "category", "category_name", "category_unique_id",
|
||||
"id", "product_id", "name", "original_name", "processed_name", "category", "category_name", "category_unique_id",
|
||||
"status", "raw_product_id", "feed_id", "gtin",
|
||||
"feed_name", "feed_last_synced_at", "raw_updated_at",
|
||||
"has_name", "has_processed_name", "has_description", "has_processed_description", "has_category", "has_attributes", "has_processed_attributes",
|
||||
@@ -1223,11 +1232,14 @@ func (s *Service) ListProcessedProductsDetailed(ctx context.Context, companyID u
|
||||
rows, err := s.Pool.Query(ctx, fmt.Sprintf(`
|
||||
SELECT p.id, p.product_id,
|
||||
`+processedPreferredNameSQL+` AS name,
|
||||
`+processedOriginalNameSQL+` AS original_name,
|
||||
p.category,
|
||||
cat.name AS category_name,
|
||||
COALESCE(cat.unique_id, NULLIF(BTRIM(p.category), '')) AS category_unique_id,
|
||||
`+processedFeedCategorySQL+` AS feed_category,
|
||||
p.status, p.raw_product_id, p.feed_id, r.gtin,
|
||||
`+processedPreferredDescriptionSQL+` AS description,
|
||||
`+processedOriginalDescriptionSQL+` AS original_description,
|
||||
p.processed_name, p.processed_description,
|
||||
COALESCE(p.meta_title, ''), COALESCE(p.meta_description, ''),
|
||||
p.attributes, p.processed_attributes, r.mapped_data,
|
||||
@@ -1241,9 +1253,10 @@ func (s *Service) ListProcessedProductsDetailed(ctx context.Context, companyID u
|
||||
}
|
||||
defer rows.Close()
|
||||
items, err := scanMaps(rows, []string{
|
||||
"id", "product_id", "name", "category", "category_name", "category_unique_id",
|
||||
"id", "product_id", "name", "original_name", "category", "category_name", "category_unique_id",
|
||||
"feed_category",
|
||||
"status", "raw_product_id", "feed_id", "gtin",
|
||||
"description", "processed_name", "processed_description",
|
||||
"description", "original_description", "processed_name", "processed_description",
|
||||
"meta_title", "meta_description",
|
||||
"attributes", "processed_attributes", "mapped_data",
|
||||
"created_at", "updated_at",
|
||||
@@ -1263,10 +1276,13 @@ func (s *Service) GetProcessedProduct(ctx context.Context, companyID, id uuid.UU
|
||||
row := s.Pool.QueryRow(ctx, `
|
||||
SELECT p.id, p.product_id,
|
||||
`+processedPreferredNameSQL+` AS name,
|
||||
`+processedOriginalNameSQL+` AS original_name,
|
||||
p.category,
|
||||
cat.name AS category_name,
|
||||
COALESCE(cat.unique_id, NULLIF(BTRIM(p.category), '')) AS category_unique_id,
|
||||
`+processedFeedCategorySQL+` AS feed_category,
|
||||
`+processedPreferredDescriptionSQL+` AS description,
|
||||
`+processedOriginalDescriptionSQL+` AS original_description,
|
||||
p.processed_name, p.processed_description,
|
||||
p.status, p.attributes, p.processed_attributes, r.gtin, r.mapped_data,
|
||||
COALESCE(p.feed_id, r.feed_id) AS feed_id,
|
||||
@@ -1285,8 +1301,9 @@ func (s *Service) GetProcessedProduct(ctx context.Context, companyID, id uuid.UU
|
||||
LEFT JOIN input_feeds f ON f.id = COALESCE(p.feed_id, r.feed_id)`+processedCategoryResolveJoin+`
|
||||
WHERE p.id = $1 AND p.company_id = $2`, id, companyID)
|
||||
item, err := scanMap(row, []string{
|
||||
"id", "product_id", "name", "category", "category_name", "category_unique_id",
|
||||
"description", "processed_name", "processed_description",
|
||||
"id", "product_id", "name", "original_name", "category", "category_name", "category_unique_id",
|
||||
"feed_category",
|
||||
"description", "original_description", "processed_name", "processed_description",
|
||||
"status", "attributes", "processed_attributes", "gtin", "mapped_data",
|
||||
"feed_id", "feed_name", "feed_last_synced_at", "raw_updated_at",
|
||||
"has_processed_name", "has_processed_description", "has_attributes", "has_processed_attributes",
|
||||
|
||||
Reference in New Issue
Block a user