up
This commit is contained in:
@@ -324,3 +324,42 @@ func PortalDownloadFactura(c *fiber.Ctx) error {
|
||||
c.Set("Content-Disposition", fmt.Sprintf(`attachment; filename="%s"`, f.OriginalName))
|
||||
return c.SendFile(clean)
|
||||
}
|
||||
|
||||
// ─── Notificaciones del portal user ──────────────────────────────────────────
|
||||
|
||||
func PortalGetMisNotifs(c *fiber.Ctx) error {
|
||||
u := middlewares.PortalUserFromLocals(c)
|
||||
if u == nil {
|
||||
return c.Status(401).JSON(fiber.Map{"error": "no autenticado"})
|
||||
}
|
||||
soloNoLeidas := c.Query("no_leidas") == "1"
|
||||
items, err := models.GetSistemaNotifs("portal_user", u.ID, soloNoLeidas)
|
||||
if err != nil {
|
||||
return c.Status(500).JSON(fiber.Map{"error": err.Error()})
|
||||
}
|
||||
count := models.CountUnreadNotifs("portal_user", u.ID)
|
||||
return c.JSON(fiber.Map{"items": items, "unread": count})
|
||||
}
|
||||
|
||||
func PortalMarcarNotifLeida(c *fiber.Ctx) error {
|
||||
u := middlewares.PortalUserFromLocals(c)
|
||||
if u == nil {
|
||||
return c.Status(401).JSON(fiber.Map{"error": "no autenticado"})
|
||||
}
|
||||
id, _ := c.ParamsInt("id")
|
||||
if err := models.MarcarNotifLeida(uint(id)); err != nil {
|
||||
return c.Status(500).JSON(fiber.Map{"error": err.Error()})
|
||||
}
|
||||
return c.JSON(fiber.Map{"ok": true})
|
||||
}
|
||||
|
||||
func PortalMarcarTodasLeidas(c *fiber.Ctx) error {
|
||||
u := middlewares.PortalUserFromLocals(c)
|
||||
if u == nil {
|
||||
return c.Status(401).JSON(fiber.Map{"error": "no autenticado"})
|
||||
}
|
||||
if err := models.MarcarTodasLeidas("portal_user", u.ID); err != nil {
|
||||
return c.Status(500).JSON(fiber.Map{"error": err.Error()})
|
||||
}
|
||||
return c.JSON(fiber.Map{"ok": true})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user