chore: build

This commit is contained in:
2026-06-12 09:52:12 +02:00
parent 2ca28e730b
commit 888932454c
3 changed files with 59 additions and 1 deletions
+39
View File
@@ -109,6 +109,45 @@ func (d *Database) DeleteUserTelegramChatID(username string) error {
return d.GDB.Model(&models.User{}).Where("username = ?", username).Update("telegram_chat_id", nil).Error
}
// GetAllLinkedTelegramAccounts retourne tous les comptes ayant un telegram_chat_id non-null.
func (d *Database) GetAllLinkedTelegramAccounts() ([]struct {
ChatID int64
Username string
Role string
}, error) {
type row struct {
ChatID int64 `gorm:"column:telegram_chat_id"`
Username string `gorm:"column:username"`
Role string `gorm:"column:role"`
}
var results []row
var clients []row
if err := d.GDB.Raw(`SELECT telegram_chat_id, username, 'client' AS role FROM clients WHERE telegram_chat_id IS NOT NULL`).Scan(&clients).Error; err != nil {
return nil, err
}
results = append(results, clients...)
var users []row
if err := d.GDB.Raw(`SELECT telegram_chat_id, username, role FROM users WHERE telegram_chat_id IS NOT NULL`).Scan(&users).Error; err != nil {
return nil, err
}
results = append(results, users...)
out := make([]struct {
ChatID int64
Username string
Role string
}, len(results))
for i, r := range results {
out[i].ChatID = r.ChatID
out[i].Username = r.Username
out[i].Role = r.Role
}
return out, nil
}
// GetUserByTelegramChatID retrouve un utilisateur (clients + users) par chat_id
func (d *Database) GetUserByTelegramChatID(chatID int64) (username, role string, err error) {
var clientResult struct {
-1
View File
@@ -2,7 +2,6 @@ package handlers
import (
"gestion/db"
"gestion/models"
"gestion/utils"
"net/http"
"strings"
+20
View File
@@ -72,6 +72,26 @@ func main() {
}
}
// Ré-enrôler tous les comptes déjà liés dans lbtelegram (au cas où lbtelegram a redémarré)
if lbService.IsConfigured() {
go func() {
accounts, err := database.GetAllLinkedTelegramAccounts()
if err != nil {
log.Printf("⚠️ [LB_SYNC] Erreur lecture comptes liés: %v", err)
return
}
ok, fail := 0, 0
for _, a := range accounts {
if err := lbService.EnrollUser(a.ChatID, a.Username, a.Role); err != nil {
fail++
} else {
ok++
}
}
log.Printf("✅ [LB_SYNC] Re-enrollment terminé: %d OK, %d échecs (total %d comptes)", ok, fail, len(accounts))
}()
}
log.Println("")
log.Println("🧹 Démarrage du nettoyage des commandes invalides...")
removed, err := database.CleanupInvalidQueueCommands()