This commit is contained in:
Lizandro Guarnizo
2026-05-19 13:09:06 -05:00
parent b1aa437bbd
commit 762ebc2afc
7 changed files with 143 additions and 5 deletions
+45
View File
@@ -177,12 +177,14 @@ func PortalGetProyectoData(c *fiber.Ctx) error {
tickets, _ := models.GetTicketsByPortalUser(u.ID)
facturas, _ := models.GetFacturasByCliente(proy.ClienteID, true)
facturasNoLeidas := models.CountUnreadFacturaNotifs(u.ID)
documentos, _ := models.GetDocumentosByProyecto(proy.ID)
return c.JSON(fiber.Map{
"proyecto": proy,
"fases": fases,
"avances": avances,
"entregables": entregables,
"documentos": documentos,
"tickets": tickets,
"facturas": facturas,
"facturasNoLeidas": facturasNoLeidas,
@@ -352,6 +354,46 @@ func PortalDownloadFactura(c *fiber.Ctx) error {
return c.SendFile(clean)
}
// PortalDownloadDocumento descarga un documento del proyecto (contrato, orden de servicio, etc.).
func PortalDownloadDocumento(c *fiber.Ctx) error {
u := middlewares.PortalUserFromLocals(c)
if u == nil {
return c.Status(401).JSON(fiber.Map{"error": "no autenticado"})
}
docID, _ := c.ParamsInt("id")
doc, err := models.GetProyectoDocumentoByID(uint(docID))
if err != nil || doc.Archivo == "" {
return c.Status(404).JSON(fiber.Map{"error": "No encontrado"})
}
// Verificar que el proyecto pertenece al cliente del portal user
proy, err := models.GetProyectoByID(doc.ProyectoID)
if err != nil {
return c.Status(404).JSON(fiber.Map{"error": "Proyecto no encontrado"})
}
fullUser, _ := models.GetPortalUserByID(u.ID)
clienteIDs := models.GetClienteIDsForPortalUser(fullUser)
hasAccess := false
for _, cid := range clienteIDs {
if cid == proy.ClienteID {
hasAccess = true
break
}
}
if !hasAccess {
return c.Status(403).JSON(fiber.Map{"error": "Sin acceso"})
}
clean := doc.Archivo
if !strings.HasPrefix(clean, "uploads/") {
return c.Status(403).JSON(fiber.Map{"error": "Acceso denegado"})
}
nombre := doc.OriginalName
if nombre == "" {
nombre = doc.Nombre
}
c.Set("Content-Disposition", fmt.Sprintf(`attachment; filename="%s"`, nombre))
return c.SendFile(clean)
}
// ─── Notificaciones del portal user ──────────────────────────────────────────
func PortalGetMisNotifs(c *fiber.Ctx) error {
@@ -429,6 +471,7 @@ func PortalGetMiPerfil(c *fiber.Ctx) error {
"telefono": full.Telefono,
"indicativo": full.Indicativo,
"pais": full.Pais,
"ciudad": full.Ciudad,
"documento": full.Documento,
"empresa": full.Empresa,
"sitio_web": full.SitioWeb,
@@ -449,6 +492,7 @@ func PortalUpdateMiPerfil(c *fiber.Ctx) error {
Telefono string `json:"telefono"`
Indicativo string `json:"indicativo"`
Pais string `json:"pais"`
Ciudad string `json:"ciudad"`
Documento string `json:"documento"`
Empresa string `json:"empresa"`
SitioWeb string `json:"sitio_web"`
@@ -479,6 +523,7 @@ func PortalUpdateMiPerfil(c *fiber.Ctx) error {
full.Telefono = req.Telefono
full.Indicativo = req.Indicativo
full.Pais = req.Pais
full.Ciudad = req.Ciudad
full.Documento = req.Documento
full.Empresa = req.Empresa
full.SitioWeb = req.SitioWeb
@@ -52,6 +52,10 @@ func CreatePortalUsuario(c *fiber.Ctx) error {
Notas string `json:"notas"`
TelegramChatID string `json:"telegram_chat_id"`
SitioWeb string `json:"sitio_web"`
Telefono string `json:"telefono"`
Indicativo string `json:"indicativo"`
Pais string `json:"pais"`
Ciudad string `json:"ciudad"`
}
var req Req
if err := c.BodyParser(&req); err != nil {
@@ -88,6 +92,10 @@ func CreatePortalUsuario(c *fiber.Ctx) error {
Notas: req.Notas,
TelegramChatID: req.TelegramChatID,
SitioWeb: req.SitioWeb,
Telefono: req.Telefono,
Indicativo: req.Indicativo,
Pais: req.Pais,
Ciudad: req.Ciudad,
}
if err := models.CreatePortalUser(u); err != nil {
return c.Status(500).JSON(fiber.Map{"error": err.Error()})
@@ -112,6 +120,10 @@ func UpdatePortalUsuario(c *fiber.Ctx) error {
Notas string `json:"notas"`
TelegramChatID string `json:"telegram_chat_id"`
SitioWeb string `json:"sitio_web"`
Telefono string `json:"telefono"`
Indicativo string `json:"indicativo"`
Pais string `json:"pais"`
Ciudad string `json:"ciudad"`
}
var req Req
if err := c.BodyParser(&req); err != nil {
@@ -137,6 +149,10 @@ func UpdatePortalUsuario(c *fiber.Ctx) error {
Notas: req.Notas,
TelegramChatID: req.TelegramChatID,
SitioWeb: req.SitioWeb,
Telefono: req.Telefono,
Indicativo: req.Indicativo,
Pais: req.Pais,
Ciudad: req.Ciudad,
}
u.ID = uint(id)
if err := models.UpdatePortalUser(u); err != nil {