Update notif_config.go
This commit is contained in:
@@ -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 ─────────────────────────────────────────────────
|
||||
|
||||
Reference in New Issue
Block a user