feat(accounts): sync updated WhatsApp account configs to database
Some checks failed
CI / Test (1.23) (push) Failing after -22m19s
CI / Test (1.22) (push) Failing after -22m12s
CI / Build (push) Failing after -22m19s
CI / Lint (push) Failing after -22m2s

This commit is contained in:
2026-02-20 23:10:46 +02:00
parent 011d9d7b21
commit 80a4c2b70a
3 changed files with 55 additions and 1 deletions

View File

@@ -7,6 +7,7 @@ import (
"git.warky.dev/wdevs/whatshooked/pkg/config"
"git.warky.dev/wdevs/whatshooked/pkg/logging"
"git.warky.dev/wdevs/whatshooked/pkg/storage"
)
// Accounts returns the list of all configured WhatsApp accounts
@@ -264,6 +265,20 @@ func (h *Handlers) UpdateAccount(w http.ResponseWriter, r *http.Request) {
return
}
// Sync updated config to database
if db := storage.GetDB(); db != nil {
accountRepo := storage.NewWhatsAppAccountRepository(db)
cfgJSON := ""
if updates.BusinessAPI != nil {
if b, err := json.Marshal(updates.BusinessAPI); err == nil {
cfgJSON = string(b)
}
}
if err := accountRepo.UpdateConfig(context.Background(), updates.ID, updates.PhoneNumber, cfgJSON, !updates.Disabled); err != nil {
logging.Warn("Failed to sync updated account config to database", "account_id", updates.ID, "error", err)
}
}
// If the account was enabled and settings changed, reconnect it
if !updates.Disabled {
// Disconnect old connection