feat(accounts): sync updated WhatsApp account configs to database
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user