From f4e31cea362d9824b60d0704bd57c8c2bcaf2d36 Mon Sep 17 00:00:00 2001 From: Martin Berka Date: Thu, 27 Feb 2025 21:29:43 +0100 Subject: [PATCH] Oprava #4, #5 --- server/src/service.ts | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/server/src/service.ts b/server/src/service.ts index c4b3a38..ecdd74b 100644 --- a/server/src/service.ts +++ b/server/src/service.ts @@ -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);