feat: podpora per-user notifikací s Discord, ntfy a Teams (#39)
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.
This commit is contained in:
32
server/src/routes/notificationRoutes.ts
Normal file
32
server/src/routes/notificationRoutes.ts
Normal file
@@ -0,0 +1,32 @@
|
||||
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;
|
||||
Reference in New Issue
Block a user