This commit is contained in:
Lizandro Guarnizo
2026-05-12 18:53:09 -05:00
parent 525d508982
commit 05141ce70e
3 changed files with 136 additions and 12 deletions
+26 -1
View File
@@ -94,7 +94,13 @@ func CreateContrato(c *fiber.Ctx) error {
if err := models.CreateContrato(m, inp.ServicioIDs); err != nil {
return c.Status(500).JSON(fiber.Map{"error": err.Error()})
}
return c.Status(201).JSON(fiber.Map{"message": "Contrato creado", "ok": true})
// Devolver el ID del contrato creado para que el frontend pueda enviar bienvenida
created, _ := models.GetUltimoContratoByCliente(inp.ClienteID)
contratoID := uint(0)
if created != nil {
contratoID = created.ID
}
return c.Status(201).JSON(fiber.Map{"message": "Contrato creado", "ok": true, "id": contratoID})
}
func UpdateContrato(c *fiber.Ctx) error {
@@ -186,6 +192,25 @@ func EnviarCorreoContrato(c *fiber.Ctx) error {
if err != nil {
return c.Status(404).JSON(fiber.Map{"error": "No encontrado"})
}
// Si se pasa regla_id, usar esa regla específica (EnviarNotificacionGrupo)
var body struct {
ReglaID uint `json:"regla_id"`
}
_ = c.BodyParser(&body)
if body.ReglaID > 0 {
regla, err := models.GetReglaByID(body.ReglaID)
if err != nil {
return c.Status(404).JSON(fiber.Map{"error": "Regla no encontrada"})
}
if err := services.EnviarNotificacionGrupo(regla, &contrato.Cliente, []models.Contrato{*contrato}); err != nil {
return c.Status(500).JSON(fiber.Map{"error": err.Error()})
}
return c.JSON(fiber.Map{"message": "Correo enviado", "ok": true})
}
// Sin regla_id → flujo manual genérico
if err := services.EnviarCorreoManual(contrato); err != nil {
return c.Status(500).JSON(fiber.Map{"error": err.Error()})
}