feat: export historie jídel uživatele
CI / Generate TypeScript types (push) Successful in 10s
CI / Server unit tests (push) Successful in 25s
CI / Build server (push) Successful in 28s
CI / Build client (push) Successful in 41s
CI / Playwright E2E tests (push) Successful in 1m53s
CI / Build and push Docker image (push) Successful in 1m1s
CI / Notify (push) Successful in 3s

This commit is contained in:
Ondřej Anděl
2026-08-12 13:53:36 +02:00
parent 065ccaf38a
commit eeb1630391
13 changed files with 1513 additions and 8 deletions
+24
View File
@@ -2,10 +2,34 @@ import express, { Request, Response } from "express";
import { getLogin } from "../auth";
import { parseToken } from "../utils";
import { getStats } from "../stats";
import { EXPORT_FORMATS, generateUserExport, isExportFormat } from "../userExport";
import { WeeklyStats } from "../../../types/gen/types.gen";
const router = express.Router();
/**
* Vrátí přehled stravování přihlášeného uživatele za vybraný měsíc (XLSX, CSV nebo JSON).
*/
router.get("/export", async (req: Request<{}, any, undefined>, res: Response) => {
const login = getLogin(parseToken(req));
const year = Number(req.query.year);
const month = Number(req.query.month);
const format = req.query.format ?? 'xlsx';
if (!Number.isInteger(year) || year < 2000 || year > 2100) {
return res.status(400).json({ error: "Neplatný rok" });
}
if (!Number.isInteger(month) || month < 1 || month > 12) {
return res.status(400).json({ error: "Neplatný měsíc" });
}
if (!isExportFormat(format)) {
return res.status(400).json({ error: `Neplatný formát exportu, podporované jsou: ${EXPORT_FORMATS.join(', ')}` });
}
const { content, mimeType, fileName } = await generateUserExport(login, year, month, format);
res.setHeader('Content-Type', mimeType);
res.setHeader('Content-Disposition', `attachment; filename="${fileName}"`);
return res.status(200).send(content);
});
router.get("/", async (req: Request<{}, any, undefined>, res: Response<WeeklyStats>) => {
getLogin(parseToken(req));
if (typeof req.query.startDate === 'string' && typeof req.query.endDate === 'string') {