Private
Public Access
refactor: estaban mal los nombres otra vez
This commit is contained in:
1 parent
8c4dcce2fc
commit
d953d0c6b4
3 files changed
+11
-11
No files matched your search
@@ -89,24 +89,24 @@ func (r *repositorioGrupo) QuitarPermiso(grupoID, permisoID uint) error {
|
||||
|
||||
func (r *repositorioGrupo) AgregarSubGrupo(padreID, hijoID uint) error {
|
||||
var padre models_seguridad.Grupo
|
||||
if err := r.db.First(&padre, padreID).Error; err != nil {
|
||||
if err := r.db.Preload("Grupos").First(&padre, padreID).Error; err != nil {
|
||||
return err
|
||||
}
|
||||
var hijo models_seguridad.Grupo
|
||||
if err := r.db.First(&hijo, hijoID).Error; err != nil {
|
||||
return err
|
||||
}
|
||||
return r.db.Model(&padre).Association("Grupos").Append(&hijo)
|
||||
padre.Grupos = append(padre.Grupos, models_seguridad.Grupo{ID: hijoID})
|
||||
return r.db.Save(&padre).Error
|
||||
}
|
||||
|
||||
func (r *repositorioGrupo) QuitarSubGrupo(padreID, hijoID uint) error {
|
||||
var padre models_seguridad.Grupo
|
||||
if err := r.db.First(&padre, padreID).Error; err != nil {
|
||||
if err := r.db.Preload("Grupos").First(&padre, padreID).Error; err != nil {
|
||||
return err
|
||||
}
|
||||
var hijo models_seguridad.Grupo
|
||||
if err := r.db.First(&hijo, hijoID).Error; err != nil {
|
||||
return err
|
||||
var nuevos []models_seguridad.Grupo
|
||||
for _, g := range padre.Grupos {
|
||||
if g.ID != hijoID {
|
||||
nuevos = append(nuevos, g)
|
||||
}
|
||||
}
|
||||
return r.db.Model(&padre).Association("Grupos").Delete(&hijo)
|
||||
padre.Grupos = nuevos
|
||||
return r.db.Save(&padre).Error
|
||||
}
|
||||
File renamed without changes.
File renamed without changes.
Reference in new issue
Block a user