import express, { Request } from "express"; import { getLogin } from "../auth"; import { parseToken } from "../utils"; import { getNotificationSettings, saveNotificationSettings } from "../notifikace"; import { UpdateNotificationSettingsData } from "../../../types"; const router = express.Router(); /** Vrátí nastavení notifikací pro přihlášeného uživatele. */ router.get("/settings", async (req, res, next) => { const login = getLogin(parseToken(req)); try { const settings = await getNotificationSettings(login); res.status(200).json(settings); } catch (e: any) { next(e) } }); /** Uloží nastavení notifikací pro přihlášeného uživatele. */ router.post("/settings", async (req: Request<{}, any, UpdateNotificationSettingsData["body"]>, res, next) => { const login = getLogin(parseToken(req)); try { const settings = await saveNotificationSettings(login, { ntfyTopic: req.body.ntfyTopic, discordWebhookUrl: req.body.discordWebhookUrl, teamsWebhookUrl: req.body.teamsWebhookUrl, enabledEvents: req.body.enabledEvents, }); res.status(200).json(settings); } catch (e: any) { next(e) } }); export default router;