up
This commit is contained in:
@@ -62,16 +62,16 @@ func GetContratos(c *fiber.Ctx) error {
|
||||
|
||||
func CreateContrato(c *fiber.Ctx) error {
|
||||
type Input struct {
|
||||
ClienteID uint `json:"cliente_id"`
|
||||
ServicioIDs []uint `json:"servicio_ids"`
|
||||
FechaInicio string `json:"fecha_inicio"`
|
||||
FechaVencimiento string `json:"fecha_vencimiento"`
|
||||
ClienteID uint `json:"cliente_id"`
|
||||
ServicioIDs []uint `json:"servicio_ids"`
|
||||
FechaInicio string `json:"fecha_inicio"`
|
||||
FechaVencimiento string `json:"fecha_vencimiento"`
|
||||
PrecioAcordado float64 `json:"precio_acordado"`
|
||||
AutoRenovar bool `json:"auto_renovar"`
|
||||
Notas string `json:"notas"`
|
||||
ServidorID *uint `json:"servidor_id"`
|
||||
ConxDbID *uint `json:"conx_db_id"`
|
||||
AiConfigID *uint `json:"ai_config_id"`
|
||||
AutoRenovar bool `json:"auto_renovar"`
|
||||
Notas string `json:"notas"`
|
||||
ServidorIDs []uint `json:"servidor_ids"`
|
||||
ConxDbIDs []uint `json:"conx_db_ids"`
|
||||
AiConfigIDs []uint `json:"ai_config_ids"`
|
||||
}
|
||||
var inp Input
|
||||
if err := c.BodyParser(&inp); err != nil {
|
||||
@@ -93,11 +93,17 @@ func CreateContrato(c *fiber.Ctx) error {
|
||||
AutoRenovar: inp.AutoRenovar,
|
||||
Notas: inp.Notas,
|
||||
Estado: "activo",
|
||||
ServidorID: inp.ServidorID,
|
||||
ConxDbID: inp.ConxDbID,
|
||||
AiConfigID: inp.AiConfigID,
|
||||
}
|
||||
if err := models.CreateContrato(m, inp.ServicioIDs); err != nil {
|
||||
if inp.ServidorIDs == nil {
|
||||
inp.ServidorIDs = []uint{}
|
||||
}
|
||||
if inp.ConxDbIDs == nil {
|
||||
inp.ConxDbIDs = []uint{}
|
||||
}
|
||||
if inp.AiConfigIDs == nil {
|
||||
inp.AiConfigIDs = []uint{}
|
||||
}
|
||||
if err := models.CreateContrato(m, inp.ServicioIDs, inp.ServidorIDs, inp.ConxDbIDs, inp.AiConfigIDs); err != nil {
|
||||
return c.Status(500).JSON(fiber.Map{"error": err.Error()})
|
||||
}
|
||||
// Devolver el ID del contrato creado para que el frontend pueda enviar bienvenida
|
||||
@@ -121,9 +127,9 @@ func UpdateContrato(c *fiber.Ctx) error {
|
||||
PrecioAcordado float64 `json:"precio_acordado"`
|
||||
AutoRenovar bool `json:"auto_renovar"`
|
||||
Notas string `json:"notas"`
|
||||
ServidorID *uint `json:"servidor_id"`
|
||||
ConxDbID *uint `json:"conx_db_id"`
|
||||
AiConfigID *uint `json:"ai_config_id"`
|
||||
ServidorIDs []uint `json:"servidor_ids"`
|
||||
ConxDbIDs []uint `json:"conx_db_ids"`
|
||||
AiConfigIDs []uint `json:"ai_config_ids"`
|
||||
}
|
||||
var inp Input
|
||||
if err := c.BodyParser(&inp); err != nil {
|
||||
@@ -145,10 +151,7 @@ func UpdateContrato(c *fiber.Ctx) error {
|
||||
existing.PrecioAcordado = inp.PrecioAcordado
|
||||
existing.AutoRenovar = inp.AutoRenovar
|
||||
existing.Notas = inp.Notas
|
||||
existing.ServidorID = inp.ServidorID
|
||||
existing.ConxDbID = inp.ConxDbID
|
||||
existing.AiConfigID = inp.AiConfigID
|
||||
if err := models.UpdateContrato(*existing, inp.ServicioIDs); err != nil {
|
||||
if err := models.UpdateContrato(*existing, inp.ServicioIDs, inp.ServidorIDs, inp.ConxDbIDs, inp.AiConfigIDs); err != nil {
|
||||
return c.Status(500).JSON(fiber.Map{"error": err.Error()})
|
||||
}
|
||||
return c.JSON(fiber.Map{"message": "Actualizado", "ok": true})
|
||||
@@ -185,12 +188,12 @@ func RenovarContrato(c *fiber.Ctx) error {
|
||||
Estado: "activo",
|
||||
Notas: "Renovación automática desde contrato #" + strconv.Itoa(int(existing.ID)),
|
||||
}
|
||||
if err := models.CreateContrato(nuevo, servicioIDs); err != nil {
|
||||
if err := models.CreateContrato(nuevo, servicioIDs, nil, nil, nil); err != nil {
|
||||
return c.Status(500).JSON(fiber.Map{"error": err.Error()})
|
||||
}
|
||||
// Marcar anterior como renovado
|
||||
existing.Estado = "renovado"
|
||||
models.UpdateContrato(*existing, nil)
|
||||
models.UpdateContrato(*existing, nil, nil, nil, nil)
|
||||
|
||||
return c.JSON(fiber.Map{"message": "Renovado", "ok": true})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user