Update notif_config.go
This commit is contained in:
@@ -3,7 +3,6 @@ package models
|
|||||||
import (
|
import (
|
||||||
"github.com/sujit-baniya/fiber-boilerplate/app"
|
"github.com/sujit-baniya/fiber-boilerplate/app"
|
||||||
"gorm.io/gorm"
|
"gorm.io/gorm"
|
||||||
"gorm.io/gorm/clause"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// ─── NotifEventoConfig ────────────────────────────────────────────────────────
|
// ─── NotifEventoConfig ────────────────────────────────────────────────────────
|
||||||
@@ -66,12 +65,21 @@ func GetNotifConfig(evento, destinatario string) *NotifEventoConfig {
|
|||||||
|
|
||||||
// UpsertNotifConfig inserta o actualiza los canales para un evento × destinatario.
|
// UpsertNotifConfig inserta o actualiza los canales para un evento × destinatario.
|
||||||
func UpsertNotifConfig(cfg *NotifEventoConfig) error {
|
func UpsertNotifConfig(cfg *NotifEventoConfig) error {
|
||||||
return app.Http.Database.DB.
|
db := app.Http.Database.DB
|
||||||
Clauses(clause.OnConflict{
|
result := db.Model(&NotifEventoConfig{}).
|
||||||
Columns: []clause.Column{{Name: "evento"}, {Name: "destinatario"}},
|
Where("evento = ? AND destinatario = ?", cfg.Evento, cfg.Destinatario).
|
||||||
DoUpdates: clause.AssignmentColumns([]string{"canal_email", "canal_telegram", "canal_sistema"}),
|
Updates(map[string]interface{}{
|
||||||
}).
|
"canal_email": cfg.CanalEmail,
|
||||||
Create(cfg).Error
|
"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 ─────────────────────────────────────────────────
|
// ─── CRUD SistemaNotificacion ─────────────────────────────────────────────────
|
||||||
|
|||||||
Reference in New Issue
Block a user