diff --git a/pkg/models/notif_config.go b/pkg/models/notif_config.go index 9b390ed..d3f2e61 100644 --- a/pkg/models/notif_config.go +++ b/pkg/models/notif_config.go @@ -3,7 +3,6 @@ package models import ( "github.com/sujit-baniya/fiber-boilerplate/app" "gorm.io/gorm" - "gorm.io/gorm/clause" ) // ─── NotifEventoConfig ──────────────────────────────────────────────────────── @@ -66,12 +65,21 @@ func GetNotifConfig(evento, destinatario string) *NotifEventoConfig { // UpsertNotifConfig inserta o actualiza los canales para un evento × destinatario. func UpsertNotifConfig(cfg *NotifEventoConfig) error { - return app.Http.Database.DB. - Clauses(clause.OnConflict{ - Columns: []clause.Column{{Name: "evento"}, {Name: "destinatario"}}, - DoUpdates: clause.AssignmentColumns([]string{"canal_email", "canal_telegram", "canal_sistema"}), - }). - Create(cfg).Error + db := app.Http.Database.DB + result := db.Model(&NotifEventoConfig{}). + Where("evento = ? AND destinatario = ?", cfg.Evento, cfg.Destinatario). + Updates(map[string]interface{}{ + "canal_email": cfg.CanalEmail, + "canal_telegram": cfg.CanalTelegram, + "canal_sistema": cfg.CanalSistema, + }) + if result.Error != nil { + return result.Error + } + if result.RowsAffected == 0 { + return db.Create(cfg).Error + } + return nil } // ─── CRUD SistemaNotificacion ─────────────────────────────────────────────────