up
This commit is contained in:
@@ -8,6 +8,7 @@ import (
|
||||
type NotificacionRegla struct {
|
||||
gorm.Model
|
||||
Nombre string `json:"nombre" gorm:"column:nombre"`
|
||||
TipoEvento string `json:"tipo_evento" gorm:"column:tipo_evento;default:'vencimiento_proximo'"` // vencimiento_proximo | ya_vencido | bienvenida | pago_recibido | manual
|
||||
DiasAntes int `json:"dias_antes" gorm:"column:dias_antes"`
|
||||
PlantillaID uint `json:"plantilla_id" gorm:"column:plantilla_id"`
|
||||
Plantilla PlantillaCorreo `json:"plantilla" gorm:"foreignKey:PlantillaID"`
|
||||
@@ -35,6 +36,16 @@ func GetReglasActivas() ([]NotificacionRegla, error) {
|
||||
return items, nil
|
||||
}
|
||||
|
||||
func GetReglasByTipoEvento(tipoEvento string) ([]NotificacionRegla, error) {
|
||||
var items []NotificacionRegla
|
||||
if err := app.Http.Database.DB.Preload("Plantilla").
|
||||
Where("activo = ? AND tipo_evento = ?", true, tipoEvento).
|
||||
Order("dias_antes DESC").Find(&items).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return items, nil
|
||||
}
|
||||
|
||||
func GetReglaByID(id uint) (*NotificacionRegla, error) {
|
||||
var item NotificacionRegla
|
||||
if err := app.Http.Database.DB.Preload("Plantilla").First(&item, id).Error; err != nil {
|
||||
@@ -50,6 +61,7 @@ func CreateRegla(r NotificacionRegla) error {
|
||||
func UpdateRegla(r NotificacionRegla) error {
|
||||
return app.Http.Database.DB.Model(&r).Updates(map[string]interface{}{
|
||||
"nombre": r.Nombre,
|
||||
"tipo_evento": r.TipoEvento,
|
||||
"dias_antes": r.DiasAntes,
|
||||
"plantilla_id": r.PlantillaID,
|
||||
"activo": r.Activo,
|
||||
|
||||
Reference in New Issue
Block a user