api for health score toggle

This commit is contained in:
2026-10-05 12:07:49 +05:30
parent 97f277f424
commit fc2caffcd1
7 changed files with 358 additions and 1 deletions

View File

@@ -33,6 +33,8 @@ type ProductService interface {
GetSaleTemplate(tenantID, locationID int) (*models.SaleTemplate, error)
FetchFilteredProducts(categoryID, subcategoryID, productID, applocationID, tenantID, locationID int, keyword, productStatus, approve string, pageno, pagesize int) ([]models.Tenantproducts, error)
GetProductByVariant(tenantid, variantid, locationid, productid int) ([]models.Products, error)
// SetShowHealthScore turns one product's health score on or off for one shop.
SetShowHealthScore(tenantID, productID int, show bool) error
GetProductsBySubcategory(params models.ProductFilter) (map[string]interface{}, error)
UpdateProductLocation(input models.Productlocations) error
CreateProductLocation(input []models.Productlocations) error
@@ -493,6 +495,10 @@ func (s *productService) ImportCatalogueProduct(reqs []models.ImportCataloguePro
Retailprice: retail,
Taxpercent: req.Taxpercent,
Approve: 1,
// Nil means the caller did not say, which is yes — see the
// field. An older console that knows nothing about this must not
// have its imports read as a deliberate no.
Showhealthscore: req.Showhealthscore == nil || *req.Showhealthscore,
}
// Everything the snapshot has no column for, kept as the catalogue
// stated it.
@@ -656,6 +662,31 @@ func decorateNutrition(nutrition NutritionService, products []models.Products) {
// same upstream record.
found := nutrition.ForProduct(products[i].Productbrand, products[i].Imageid)
products[i].Nutrition = found.Panel
products[i].Healthscore = found.Health
// The score is the shop's to show or not. The figures are not.
//
// A merchant turning this off is saying "that rating does not describe
// what I sell" — which is a judgement about a judgement, made by
// somebody holding the packet. It says nothing about the grams, so
// `Nutrition` above is set either way.
if products[i].Showhealthscore {
products[i].Healthscore = found.Health
}
}
}
// SetShowHealthScore turns one product's health score on or off for one shop.
//
// The merchant's decision, not Nearle's. The score comes from a third party
// matching a reference product by name — frequently under 60% confidence — and
// a shopkeeper holding the packet is better placed than that matcher to say
// whether the rating describes what they sell.
//
// Only the score moves. The nutrition figures are what the label states and are
// sent either way; turning this off disputes the judgement, not the grams.
func (s *productService) SetShowHealthScore(tenantID, productID int, show bool) error {
if tenantID <= 0 || productID <= 0 {
return fmt.Errorf("tenantid and productid are both required")
}
return s.repo.SetShowHealthScore(tenantID, productID, show)
}