feat(prov_servidor): add many2many integrations linking

- ProvServidor model: add Integraciones []Submodules (many2many:prov_servidor_submodules)
- GetAllProvServidor: preload Integraciones
- SetProvServidorIntegraciones: new model func to replace associations
- New endpoint PUT /app/provservidor/:id/integraciones
- GetSubmodules: support ?limit= query param
- prov_servidor.html: show integrations as badges in table, view modal,
  and edit modal with checkboxes to select one or more existing submodules

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
Lizandro Guarnizo
2026-05-21 10:34:01 -05:00
co-authored by Copilot
parent c834e40e83
commit b4b60810a1
5 changed files with 145 additions and 38 deletions
@@ -115,3 +115,26 @@ func DeleteProvServidor(c *fiber.Ctx) error {
"message": "Proveedor de servidor eliminado exitosamente",
})
}
func SetProvServidorIntegraciones(c *fiber.Ctx) error {
uid, err := strconv.ParseUint(c.Params("id"), 10, 32)
if err != nil {
return c.Status(fiber.StatusBadRequest).JSON(fiber.Map{"message": "ID inválido"})
}
var body struct {
SubmoduleIDs []uint `json:"submodule_ids"`
}
if err := c.BodyParser(&body); err != nil {
return c.Status(fiber.StatusBadRequest).JSON(fiber.Map{"message": "Error parsing body"})
}
if err := models.SetProvServidorIntegraciones(uint(uid), body.SubmoduleIDs); err != nil {
return c.Status(fiber.StatusInternalServerError).JSON(fiber.Map{
"message": "Error actualizando integraciones",
"error": err.Error(),
})
}
return c.JSON(fiber.Map{"message": "Integraciones actualizadas"})
}
+5 -1
View File
@@ -39,7 +39,11 @@ func GetSubmodules(c *fiber.Ctx) error {
}
searchQuery := c.Query("search", "") // Obtener el término de búsqueda
limit := 10 // Número de módulos por página
limitStr := c.Query("limit", "10")
limit, _ := strconv.Atoi(limitStr)
if limit <= 0 {
limit = 10
}
offset := (page - 1) * limit
// Llama a AllModules con el término de búsqueda