Oprava #4, #5
All checks were successful
ci/woodpecker/push/workflow Pipeline was successful

This commit is contained in:
Martin Berka 2025-02-27 21:29:43 +01:00
parent 8dda6b1014
commit f4e31cea36

View File

@ -367,7 +367,16 @@ export async function addChoice(login: string, trusted: boolean, locationKey: Lo
* @param date datum, pro které je validace prováděna
*/
async function validateFoodIndex(locationKey: LocationKey, foodIndex?: number, date?: Date) {
if (locationKey in Restaurants && foodIndex != null) {
if (foodIndex != null) {
if (typeof foodIndex !== 'number') {
throw Error(`Neplatný index ${foodIndex} typu ${typeof foodIndex}`);
}
if (foodIndex < 0) {
throw Error(`Neplatný index ${foodIndex}`);
}
if (!(locationKey in Restaurants)) {
throw Error(`Neplatný index ${foodIndex} pro lokalitu ${locationKey} nepodporující indexy`);
}
const usedDate = date ?? getToday();
const restaurantKey = Restaurants[locationKey as keyof typeof Restaurants]
const menu = await getRestaurantMenu(restaurantKey, usedDate);