This commit is contained in:
parent
62cc82da9a
commit
4c2b08adf8
@ -1,10 +1,10 @@
|
||||
import express, { Request } from "express";
|
||||
import express, { Request, Response } from "express";
|
||||
import { getLogin, getTrusted } from "../auth";
|
||||
import { addChoice, getDateForWeekIndex, getToday, removeChoice, removeChoices, updateDepartureTime, updateNote } from "../service";
|
||||
import { getDayOfWeekIndex, parseToken } from "../utils";
|
||||
import { getDayOfWeekIndex, parseToken, getFirstWorkDayOfWeek } from "../utils";
|
||||
import { getWebsocket } from "../websocket";
|
||||
import { callNotifikace } from "../notifikace";
|
||||
import { AddChoiceData, ChangeDepartureTimeData, RemoveChoiceData, RemoveChoicesData, UdalostEnum, UpdateNoteData } from "../../../types/gen/types.gen";
|
||||
import { AddChoiceData, ChangeDepartureTimeData, RemoveChoiceData, RemoveChoicesData, UdalostEnum, UpdateNoteData, getRestaurantMenu } from "../../../types/gen/types.gen";
|
||||
|
||||
/**
|
||||
* Ověří a vrátí index dne v týdnu z požadavku, za předpokladu, že byl předán, a je zároveň
|
||||
@ -141,4 +141,27 @@ router.post("/jdemeObed", async (req, res, next) => {
|
||||
} catch (e: any) { next(e) }
|
||||
});
|
||||
|
||||
// /api/food/refresh?type=week&heslo=docasnyheslo
|
||||
router.get("/refresh", async (req: Request, res: Response) => {
|
||||
const { type, heslo } = req.query as { type?: string; heslo?: string };
|
||||
if (heslo !== "docasnyheslo") {
|
||||
return res.status(403).json({ error: "Neplatné heslo" });
|
||||
}
|
||||
if (type !== "week") {
|
||||
return res.status(400).json({ error: "Neznámý typ refresh" });
|
||||
}
|
||||
try {
|
||||
// Pro všechny restaurace refreshni menu na aktuální týden
|
||||
const restaurants = ["SLADOVNICKA", "TECHTOWER", "ZASTAVKAUMICHALA", "SENKSERIKOVA"] as const;
|
||||
const firstDay = getFirstWorkDayOfWeek(getToday());
|
||||
const results: Record<string, any> = {};
|
||||
for (const rest of restaurants) {
|
||||
results[rest] = await getRestaurantMenu(rest, firstDay);
|
||||
}
|
||||
res.status(200).json({ ok: true, refreshed: results });
|
||||
} catch (e: any) {
|
||||
res.status(500).json({ error: e?.message || "Chyba při refreshi" });
|
||||
}
|
||||
});
|
||||
|
||||
export default router;
|
Loading…
x
Reference in New Issue
Block a user