This commit is contained in:
Lizandro Guarnizo
2026-05-15 21:01:30 -05:00
parent 5555514929
commit 5ec5595196
13 changed files with 788 additions and 9 deletions
+24 -2
View File
@@ -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.")
}