Serverová validace času odchodu

This commit is contained in:
2023-09-24 08:38:40 +02:00
parent c286bd1778
commit e4451e299a
4 changed files with 38 additions and 24 deletions

View File

@@ -1,5 +1,5 @@
import { InsufficientPermissions, formatDate, getDayOfWeekIndex, getHumanDate, getHumanTime, getIsWeekend } from "./utils";
import { ClientData, Locations, Restaurants, Menu } from "../../types";
import { ClientData, Locations, Restaurants, Menu, DepartureTime } from "../../types";
import getStorage from "./storage";
import { getMenuSladovnicka, getMenuTechTower, getMenuUMotliku } from "./restaurants";
import { getTodayMock } from "./mock";
@@ -29,7 +29,14 @@ export const getDateForWeekIndex = (index: number) => {
/** Vrátí "prázdná" (implicitní) data pro předaný den. */
function getEmptyData(date?: Date): ClientData {
const usedDate = date || getToday();
return { date: getHumanDate(usedDate), isWeekend: getIsWeekend(usedDate), weekIndex: getDayOfWeekIndex(usedDate), todayWeekIndex: getDayOfWeekIndex(getToday()), choices: {} };
return {
date: getHumanDate(usedDate),
isWeekend: getIsWeekend(usedDate),
weekIndex: getDayOfWeekIndex(usedDate),
todayWeekIndex: getDayOfWeekIndex(getToday()),
choices: {},
departureTimes: Object.values(DepartureTime),
};
}
/**
@@ -246,6 +253,9 @@ export async function updateDepartureTime(login: string, time?: string, date?: D
if (!time?.length) {
delete found[login].departureTime;
} else {
if (!Object.values<string>(DepartureTime).includes(time)) {
throw Error(`Neplatný čas odchodu ${time}`);
}
found[login].departureTime = time;
}
await storage.setData(selectedDate, clientData);