feat: multi-query/upload .sql en query runner + selector BD por rol

This commit is contained in:
Lizandro Guarnizo
2026-07-30 09:19:24 -05:00
parent 28affb5a55
commit 1d7bfd3596
8 changed files with 337 additions and 14 deletions
+27 -2
View File
@@ -69,6 +69,12 @@ func GetRoles(c *fiber.Ctx) error {
// })
// }
// Obtener todas las conexiones disponibles para asignar a roles
conexiones, err := models.GetConxDbSelect("")
if err != nil {
conexiones = []models.ConxDb{}
}
// Calcular el total de páginas
totalPages := int(math.Ceil(float64(total) / float64(limit)))
@@ -76,6 +82,7 @@ func GetRoles(c *fiber.Ctx) error {
return c.JSON(fiber.Map{
"roles": roles,
"modules": modules,
"conexiones": conexiones,
"total": total, // Total de disponibles
"totalPages": totalPages, // Total de páginas
"page": page, // Página actual
@@ -128,10 +135,18 @@ func UpdateRole(c *fiber.Ctx) error {
newSubmodules = append(newSubmodules, newSubmodule)
}
}
// Asignar los nuevos submódulos al rol
m.Submodules = newSubmodules
// Agregar las nuevas conexiones a BD
var newConxDBs []models.ConxDb
for _, db := range m.ConxDBs {
var found models.ConxDb
if err := app.Http.Database.DB.First(&found, db.ID).Error; err == nil {
newConxDBs = append(newConxDBs, found)
}
}
m.ConxDBs = newConxDBs
// Actualizar el rol en la base de datos
if err := app.Http.Database.DB.Session(&gorm.Session{FullSaveAssociations: true}).Save(&m).Error; err != nil {
return c.Status(fiber.StatusInternalServerError).JSON(fiber.Map{
@@ -158,6 +173,16 @@ func CreateRole(c *fiber.Ctx) error {
})
}
// Look up ConxDBs by ID
var conxDbs []models.ConxDb
for _, db := range m.ConxDBs {
var found models.ConxDb
if err := app.Http.Database.DB.First(&found, db.ID).Error; err == nil {
conxDbs = append(conxDbs, found)
}
}
m.ConxDBs = conxDbs
// Create the role in the database
if err := models.CreateRole(m); err != nil {
return c.Status(fiber.StatusInternalServerError).JSON(fiber.Map{