diff --git a/client/src/App.tsx b/client/src/App.tsx index de3508c..4b4ce18 100644 --- a/client/src/App.tsx +++ b/client/src/App.tsx @@ -214,10 +214,6 @@ function App() { const saveNote = async (note?: string) => { if (auth?.login) { - if (note != null && note.length > 70) { - alert("Poznámka může mít maximálně 70 znaků"); - return; - } await errorHandler(() => updateNote(note, dayIndex)); setNoteModalOpen(false); } @@ -373,8 +369,7 @@ function App() { Poslední změny: {dayIndex != null && diff --git a/server/src/routes/foodRoutes.ts b/server/src/routes/foodRoutes.ts index 322db47..9a2987d 100644 --- a/server/src/routes/foodRoutes.ts +++ b/server/src/routes/foodRoutes.ts @@ -97,20 +97,20 @@ router.post("/updateNote", async (req, res, next) => { const login = getLogin(parseToken(req)); const trusted = getTrusted(parseToken(req)); const note = req.body.note; - if (note && note.length > 70) { - throw Error("Poznámka může mít maximálně 70 znaků"); - } - let date = undefined; - if (req.body.dayIndex != null) { - let dayIndex; - try { - dayIndex = parseValidateFutureDayIndex(req); - } catch (e: any) { - return res.status(400).json({ error: e.message }); - } - date = getDateForWeekIndex(dayIndex); - } try { + if (note && note.length > 70) { + throw Error("Poznámka může mít maximálně 70 znaků"); + } + let date = undefined; + if (req.body.dayIndex != null) { + let dayIndex; + try { + dayIndex = parseValidateFutureDayIndex(req); + } catch (e: any) { + return res.status(400).json({ error: e.message }); + } + date = getDateForWeekIndex(dayIndex); + } const data = await updateNote(login, trusted, note, date); getWebsocket().emit("message", await addVolatileData(data)); res.status(200).json(data); diff --git a/server/src/routes/pizzaDayRoutes.ts b/server/src/routes/pizzaDayRoutes.ts index c23aa9e..e20a44a 100644 --- a/server/src/routes/pizzaDayRoutes.ts +++ b/server/src/routes/pizzaDayRoutes.ts @@ -85,14 +85,16 @@ router.post("/finishDelivery", async (req, res) => { res.status(200).json({}); }); -router.post("/updatePizzaDayNote", async (req, res) => { +router.post("/updatePizzaDayNote", async (req, res, next) => { const login = getLogin(parseToken(req)); - if (req.body.note && req.body.note.length > 70) { - throw Error("Poznámka může mít maximálně 70 znaků"); - } - const data = await updatePizzaDayNote(login, req.body.note); - getWebsocket().emit("message", await addVolatileData(data)); - res.status(200).json(data); + try { + if (req.body.note && req.body.note.length > 70) { + throw Error("Poznámka může mít maximálně 70 znaků"); + } + const data = await updatePizzaDayNote(login, req.body.note); + getWebsocket().emit("message", await addVolatileData(data)); + res.status(200).json(data); + } catch (e: any) { next(e) } }); router.post("/updatePizzaFee", async (req, res, next) => {