import { Router } from "express"; import { requireAuth } from "../auth/middleware.js"; import { getAlerts } from "../services/alerts.js"; import { ticketsForAlerts, type AlertTicketInfo } from "../services/alertTickets.js"; import { asyncHandler } from "../utils/asyncHandler.js"; export const alertsRouter = Router(); alertsRouter.use(requireAuth); // Everyone signed in can see it — it's the same server, disk and backup status the other pages already show. // `?refresh=1` asks for a fresh check instead of a recent one. alertsRouter.get("/", asyncHandler(async (req, res) => { const report = await getAlerts(req.query.refresh === "1"); // The ticket opened for each alert, if there is one. Never allowed to stop the page from loading. let tickets = new Map(); try { tickets = await ticketsForAlerts(report.alerts.map((a) => a.id)); } catch (err) { console.error("[alerts] couldn't look up tickets:", err); } res.json({ ...report, alerts: report.alerts.map((a) => ({ ...a, ticket: tickets.get(a.id) ?? null })) }); }));