From 60563eaf0d1bea1fe8a6e9771b2cd86d310fa5ce Mon Sep 17 00:00:00 2001
From: Martin Berka <martin.berka@radbuza.net>
Date: Mon, 16 Oct 2023 09:56:22 +0200
Subject: [PATCH] =?UTF-8?q?Oprava=20sestavov=C3=A1n=C3=AD=20URL=20pro=20nt?=
 =?UTF-8?q?fy?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 server/src/notifikace.ts        | 7 +++----
 server/src/routes/foodRoutes.ts | 1 +
 2 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/server/src/notifikace.ts b/server/src/notifikace.ts
index 7dcf4c4..ffbb251 100644
--- a/server/src/notifikace.ts
+++ b/server/src/notifikace.ts
@@ -73,12 +73,14 @@ export const ntfyCall = async (data: NotififaceInput) => {
     const today = formatDate(getToday());
     let clientData: ClientData = await storage.getData(today);
     const userByCLocation = getUsersByLocation(clientData.choices, data.user)
+    // Odstraníme mezery a diakritiku a převedeme na lowercase
+    const topic = data.user.normalize('NFD').replace(' ', '').replace(/[\u0300-\u036f]/g, '').toLowerCase();
 
     const token = Buffer.from(`${username}:${password}`, 'utf8').toString('base64');
     const promises = userByCLocation.map(async user => {
         try {
             const response = await axios({
-                url: `${url}/${user}`,
+                url: `${url}/${topic}`,
                 method: 'POST',
                 data: `${data.udalost} - spustil:${data.user}`,
                 headers: {
@@ -99,9 +101,6 @@ export const ntfyCall = async (data: NotififaceInput) => {
 export const callNotifikace = async ({ input, teams = true, gotify = false, ntfy = true }: NotifikaceData) => {
     const notifications = [];
     if (ntfy) {
-        if (input.user) {
-            input.user = input.user.normalize('NFD').replace(' ', '').replace(/[\u0300-\u036f]/g, '').toLowerCase();
-        }
         const ntfyPromises = await ntfyCall(input);
         if (ntfyPromises) {
             notifications.push(...ntfyPromises);
diff --git a/server/src/routes/foodRoutes.ts b/server/src/routes/foodRoutes.ts
index 079654b..e115228 100644
--- a/server/src/routes/foodRoutes.ts
+++ b/server/src/routes/foodRoutes.ts
@@ -116,6 +116,7 @@ router.post("/jdemeObed", async (req, res, next) => {
     const login = getLogin(parseToken(req));
     try {
         await callNotifikace({ input: { user: login, udalost: UdalostEnum.JDEME_OBED }, gotify: false })
+        res.status(200).json({});
     } catch (e: any) { next(e) }
 });