chore: build
This commit is contained in:
@@ -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
|
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
|
// GetUserByTelegramChatID retrouve un utilisateur (clients + users) par chat_id
|
||||||
func (d *Database) GetUserByTelegramChatID(chatID int64) (username, role string, err error) {
|
func (d *Database) GetUserByTelegramChatID(chatID int64) (username, role string, err error) {
|
||||||
var clientResult struct {
|
var clientResult struct {
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ package handlers
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"gestion/db"
|
"gestion/db"
|
||||||
"gestion/models"
|
|
||||||
"gestion/utils"
|
"gestion/utils"
|
||||||
"net/http"
|
"net/http"
|
||||||
"strings"
|
"strings"
|
||||||
|
|||||||
@@ -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("")
|
||||||
log.Println("🧹 Démarrage du nettoyage des commandes invalides...")
|
log.Println("🧹 Démarrage du nettoyage des commandes invalides...")
|
||||||
removed, err := database.CleanupInvalidQueueCommands()
|
removed, err := database.CleanupInvalidQueueCommands()
|
||||||
|
|||||||
Reference in New Issue
Block a user