diff --git a/client/src/App.tsx b/client/src/App.tsx index 37b8bc8..68d7d23 100644 --- a/client/src/App.tsx +++ b/client/src/App.tsx @@ -637,9 +637,11 @@ function App() { } else { content =
Chyba načtení dat
} + // Zavřený podnik nelze vybrat kliknutím na záhlaví + const canSelectLocation = canChangeChoice && !menu?.closed; return
-
doAddClickFoodChoice(location)}> +
canSelectLocation && doAddClickFoodChoice(location)}>

{getLunchChoiceName(location)} diff --git a/server/src/service.ts b/server/src/service.ts index abe761b..1d3da17 100644 --- a/server/src/service.ts +++ b/server/src/service.ts @@ -489,6 +489,7 @@ export async function addChoice(login: string, trusted: boolean, locationKey: Lu if (isRestaurantDisabled(locationKey)) { throw new Error(`Podnik ${locationKey} je dočasně uzavřen`); } + await validateRestaurantOpen(locationKey, usedDate); await validateFoodIndex(locationKey, foodIndex, date); if (!slot || slot === MealSlot.OBED) { @@ -540,6 +541,21 @@ export async function addChoice(login: string, trusted: boolean, locationKey: Lu return data; } +/** + * Ověří, že vybraný podnik má v daný den otevřeno. + * + * @param locationKey vybraná lokalita + * @param date datum, pro které je validace prováděna + */ +async function validateRestaurantOpen(locationKey: LunchChoice, date: Date) { + if (Object.keys(Restaurant).includes(locationKey)) { + const menu = await getRestaurantMenu(locationKey as Restaurant, date); + if (menu.closed) { + throw new Error(`Podnik ${locationKey} má v tento den zavřeno`); + } + } +} + /** * Zvaliduje platnost indexu jídla pro vybranou lokalitu a datum. *