feat: předělání historie a profilu

This commit is contained in:
Ondřej Anděl committed 2026-10-07 14:48:21 +02:00
1 parent 9e72f431a1
commit 8fa7f601f2
97 files changed
+7502 -1034

No files matched your search

+29 -1
View File
@@ -1,5 +1,8 @@
import express, { Request, Response, NextFunction } from "express";
import { addMeal, deleteMeal, getDay, getRange, setMealMultiplier, updateMeal } from "../meals";
import {
addMeal, deleteMeal, fillSameNameMeals, getDay, getMealHistory, getMealSources, getRange, setMealMultiplier,
updateMeal,
} from "../meals";
import { getDayOverview } from "../dayOverview";
import { getLogin } from "../auth";
import { formatDate, getToday, parseToken, requireIsoDate } from "../utils";
@@ -31,6 +34,31 @@ router.get("/range", async (req: Request, res: Response, next: NextFunction) =>
} catch (e) { next(e); }
});
/** Vrátí jídla z historie, každý název jednou — pro našeptávání při zakládání jídla. */
router.get("/history", async (req: Request, res: Response, next: NextFunction) => {
try {
const login = getLogin(parseToken(req));
res.status(200).json(await getMealHistory(login));
} catch (e) { next(e); }
});
/** Vrátí zdroje jídel, které uživatel už použil — nabídka pro pole Zdroj. */
router.get("/sources", async (req: Request, res: Response, next: NextFunction) => {
try {
const login = getLogin(parseToken(req));
res.status(200).json(await getMealSources(login));
} catch (e) { next(e); }
});
/** Doplní energii a živiny jídla do ostatních jídel stejného názvu, která je nemají. */
router.post("/fillSameName", async (req: Request, res: Response, next: NextFunction) => {
try {
const login = getLogin(parseToken(req));
const { id, date, dryRun } = req.body ?? {};
res.status(200).json(await fillSameNameMeals(login, id, date, dryRun === true));
} catch (e) { next(e); }
});
/** Přidá jídlo do zvoleného dne. */
router.post("/add", async (req: Request, res: Response, next: NextFunction) => {
try {