up
This commit is contained in:
+24
-2
@@ -81,8 +81,9 @@ func Migrate() {
|
||||
&models.ProyectoEntregable{},
|
||||
&models.ProyectoTicket{},
|
||||
&models.TicketMensaje{},
|
||||
&models.Factura{},
|
||||
); err != nil {
|
||||
&models.Factura{}, // Sistema de notificaciones
|
||||
&models.NotifEventoConfig{},
|
||||
&models.SistemaNotificacion{}, ); err != nil {
|
||||
log.Fatalf("Error during main migration: %v", err)
|
||||
}
|
||||
|
||||
@@ -850,3 +851,24 @@ func SeedPortalClientes() {
|
||||
}
|
||||
log.Println("[SEED] Seed de Portal de Clientes completado.")
|
||||
}
|
||||
|
||||
// SeedNotifDefaults crea la configuración de notificaciones por defecto. Es idempotente.
|
||||
func SeedNotifDefaults() {
|
||||
db := app.Http.Database.DB
|
||||
defaults := []models.NotifEventoConfig{
|
||||
{Evento: "ticket_nuevo", Destinatario: "admin", CanalEmail: true, CanalTelegram: false, CanalSistema: true, Descripcion: "Admin recibe cuando el cliente abre un ticket"},
|
||||
{Evento: "ticket_respuesta_cliente", Destinatario: "admin", CanalEmail: true, CanalTelegram: false, CanalSistema: true, Descripcion: "Admin recibe cuando el cliente responde un ticket"},
|
||||
{Evento: "ticket_respuesta_admin", Destinatario: "portal_user", CanalEmail: true, CanalTelegram: false, CanalSistema: true, Descripcion: "Cliente recibe cuando el admin responde su ticket"},
|
||||
}
|
||||
for _, cfg := range defaults {
|
||||
var existing models.NotifEventoConfig
|
||||
if err := db.Where("evento = ? AND destinatario = ?", cfg.Evento, cfg.Destinatario).First(&existing).Error; err != nil {
|
||||
if err := db.Create(&cfg).Error; err != nil {
|
||||
log.Printf("[SEED] Error creando notif config %s/%s: %v", cfg.Evento, cfg.Destinatario, err)
|
||||
} else {
|
||||
log.Printf("[SEED] Notif config creada: %s → %s", cfg.Evento, cfg.Destinatario)
|
||||
}
|
||||
}
|
||||
}
|
||||
log.Println("[SEED] Seed de notificaciones completado.")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user