Uživatelé mohou v nastavení konfigurovat vlastní webhook URL/topic pro Discord, MS Teams a ntfy, a zvolit události k odběru. Notifikace jsou odesílány pouze uživatelům se stejnou zvolenou lokalitou.
33 lines
1.2 KiB
TypeScript
33 lines
1.2 KiB
TypeScript
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;
|