chore: build
This commit is contained in:
@@ -510,7 +510,7 @@ func UpdateProduct(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
_, err = database.GetProductByID(id)
|
||||
current, err := database.GetProductByID(id)
|
||||
if err != nil {
|
||||
c.JSON(http.StatusNotFound, gin.H{"error": "Produit non trouvé"})
|
||||
return
|
||||
@@ -574,6 +574,25 @@ func UpdateProduct(c *gin.Context) {
|
||||
}
|
||||
}
|
||||
|
||||
// L'unité n'est qu'un libellé : la changer réinterpréterait les quantités des paniers et commandes en cours.
|
||||
if current.Unit != "" && updateData.Unit != current.Unit {
|
||||
baskets, commands, err := database.CountOpenProductUsage(id)
|
||||
if err != nil {
|
||||
utils.ServerErr(c, "Erreur vérification paniers et commandes", err)
|
||||
return
|
||||
}
|
||||
if baskets > 0 || commands > 0 {
|
||||
c.JSON(http.StatusConflict, gin.H{
|
||||
"error": fmt.Sprintf("Impossible de changer l'unité (%s → %s) : produit présent dans %d panier(s) et %d commande(s) en cours", current.Unit, updateData.Unit, baskets, commands),
|
||||
"open_baskets": baskets,
|
||||
"open_commands": commands,
|
||||
"current_unit": current.Unit,
|
||||
"requested_unit": updateData.Unit,
|
||||
})
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
log.Printf("🔄 [UpdateProduct] %s met à jour produit #%d", username, id)
|
||||
|
||||
comingSoon := false
|
||||
|
||||
Reference in New Issue
Block a user