fix: fixup adresse correction
Backend - Build & Lint / build (push) Failing after 33m6s
Frontend Client - EAS Build / build (push) Successful in 2h3m29s
Frontend Web - Build & Lint / build (push) Failing after 10m16s

This commit is contained in:
Xor290
2026-08-04 18:08:50 +02:00
parent c35f99b410
commit 39216fc137
6 changed files with 96 additions and 28 deletions
+21 -6
View File
@@ -3,19 +3,34 @@ package db
import (
"fmt"
"gestion/models"
"gestion/utils"
)
func (d *Database) CheckAddress(addressByUser *models.Command) error {
var correction models.Address
result := d.GDB.Where("invalid_address = ?", addressByUser.DeliveryAddress).First(&correction)
if result.Error != nil {
if isNotFound(result.Error) {
return nil
}
if result.Error == nil {
addressByUser.DeliveryAddress = correction.CorrectAddress
return fmt.Errorf("adresse invalide %s", correction.CorrectAddress)
}
if !isNotFound(result.Error) {
return fmt.Errorf("checkAddress: %w", result.Error)
}
addressByUser.DeliveryAddress = correction.CorrectAddress
return fmt.Errorf("adresse invalide %s", correction.CorrectAddress)
// Pas de correspondance exacte — fallback sur une comparaison normalisée
// (accents/casse/espaces) pour rattraper les variantes mineures de saisie.
corrections, err := d.AllAddress()
if err != nil {
return nil
}
normalizedInput := utils.NormalizeAddress(addressByUser.DeliveryAddress)
for _, c := range corrections {
if utils.NormalizeAddress(c.InvalidAddress) == normalizedInput {
addressByUser.DeliveryAddress = c.CorrectAddress
return fmt.Errorf("adresse invalide %s", c.CorrectAddress)
}
}
return nil
}
func (d *Database) AddAddress(CorrectAddressByAdmin string, InvalidAddressByAdmin string) error {