Private
Public Access
feat: hecha parte del back para crear clientes y correjida alta de
miembros Signed-off-by: fede <federico.nicolas.polidoro@gmail.com>
This commit is contained in:
1 parent
37f1741a77
commit
405eaca25c
20 files changed
+417
-112
No files matched your search
@@ -0,0 +1,51 @@
|
||||
package empresa
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
models_seguridad "repuestera_back/models/seguridad"
|
||||
r "repuestera_back/repositorios"
|
||||
"repuestera_back/utils"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
func AltaMiembro(c *gin.Context) {
|
||||
usuarioID, err := strconv.ParseUint(c.Param("id"), 10, 64)
|
||||
if err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": "ID inválido"})
|
||||
return
|
||||
}
|
||||
|
||||
empresaID := utils.EmpresaID(c)
|
||||
repo := r.ObtenerRepositorios()
|
||||
callerRol := models_seguridad.RolEmpresa(utils.EmpresaRol(c))
|
||||
|
||||
miembro, err := repo.Empresa.MiembrosIncluyendoEliminados(empresaID, uint(usuarioID))
|
||||
if err != nil {
|
||||
c.JSON(http.StatusNotFound, gin.H{"error": "El usuario no pertenece a esta empresa"})
|
||||
return
|
||||
}
|
||||
|
||||
if err := puedeModificarMiembro(c, callerRol, miembro.Rol); err != nil {
|
||||
c.JSON(http.StatusForbidden, gin.H{"error": err.Error()})
|
||||
return
|
||||
}
|
||||
|
||||
if !miembro.DeletedAt.Valid {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": "El miembro ya está activo"})
|
||||
return
|
||||
}
|
||||
|
||||
if err := repo.Empresa.RestaurarMiembro(empresaID, uint(usuarioID)); err != nil {
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
||||
return
|
||||
}
|
||||
|
||||
miembro.DeletedAt = gorm.DeletedAt{}
|
||||
miembro.Activo = true
|
||||
|
||||
c.JSON(http.StatusOK, respuestaMiembro(*miembro))
|
||||
}
|
||||
Reference in new issue
Block a user