Compare commits
12 Commits
feat/enumF
...
c311cc2fd7
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c311cc2fd7 | ||
|
|
a9fe369abc | ||
|
|
ea9fe980f0 | ||
|
|
d367826ce0 | ||
|
|
fdf1ae938f | ||
| 57c22958be | |||
|
|
fe9cee3a80 | ||
|
|
1d995faf8e | ||
|
|
62fff22a12 | ||
|
|
0fd1482810 | ||
| 02de6691a8 | |||
| 774cb4f9d2 |
@@ -31,9 +31,8 @@
|
|||||||
"vite-tsconfig-paths": "^5.1.4"
|
"vite-tsconfig-paths": "^5.1.4"
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"copy-types": "cp -r ../types ./src",
|
"start": "yarn vite",
|
||||||
"start": "yarn copy-types && vite",
|
"build": "yarn vite build"
|
||||||
"build": "yarn copy-types && vite build"
|
|
||||||
},
|
},
|
||||||
"eslintConfig": {
|
"eslintConfig": {
|
||||||
"extends": [
|
"extends": [
|
||||||
|
|||||||
@@ -8,19 +8,18 @@ import { Alert, Button, Col, Form, Row, Table } from 'react-bootstrap';
|
|||||||
import Header from './components/Header';
|
import Header from './components/Header';
|
||||||
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'
|
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'
|
||||||
import PizzaOrderList from './components/PizzaOrderList';
|
import PizzaOrderList from './components/PizzaOrderList';
|
||||||
import SelectSearch, { SelectedOptionValue } from 'react-select-search';
|
import SelectSearch, {SelectedOptionValue, SelectSearchOption} from 'react-select-search';
|
||||||
import 'react-select-search/style.css';
|
import 'react-select-search/style.css';
|
||||||
import './App.scss';
|
import './App.scss';
|
||||||
import { SelectSearchOption } from 'react-select-search';
|
|
||||||
import { faCircleCheck, faNoteSticky, faTrashCan } from '@fortawesome/free-regular-svg-icons';
|
import { faCircleCheck, faNoteSticky, faTrashCan } from '@fortawesome/free-regular-svg-icons';
|
||||||
import { useSettings } from './context/settings';
|
import { useSettings } from './context/settings';
|
||||||
import { ClientData, Restaurants, Food, Order, Locations, PizzaOrder, PizzaDayState, FoodChoices, DayMenu, DepartureTime } from './types';
|
import { ClientData, Restaurants, Food, Order, Locations, PizzaOrder, PizzaDayState, FoodChoices, DayMenu, DepartureTime, LocationKey } from '../../types';
|
||||||
import Footer from './components/Footer';
|
import Footer from './components/Footer';
|
||||||
import { faChainBroken, faChevronLeft, faChevronRight, faGear, faSatelliteDish, faSearch } from '@fortawesome/free-solid-svg-icons';
|
import { faChainBroken, faChevronLeft, faChevronRight, faGear, faSatelliteDish, faSearch } from '@fortawesome/free-solid-svg-icons';
|
||||||
import Loader from './components/Loader';
|
import Loader from './components/Loader';
|
||||||
import { getData, errorHandler, getQrUrl } from './api/Api';
|
import { getData, errorHandler, getQrUrl } from './api/Api';
|
||||||
import { addChoice, removeChoices, removeChoice, changeDepartureTime, jdemeObed, updateNote } from './api/FoodApi';
|
import { addChoice, removeChoices, removeChoice, changeDepartureTime, jdemeObed, updateNote } from './api/FoodApi';
|
||||||
import { getHumanDateTime } from './Utils';
|
import { getHumanDateTime, isInTheFuture } from './Utils';
|
||||||
import NoteModal from './components/modals/NoteModal';
|
import NoteModal from './components/modals/NoteModal';
|
||||||
import { useEasterEgg } from './context/eggs';
|
import { useEasterEgg } from './context/eggs';
|
||||||
import { getImage } from './api/EasterEggApi';
|
import { getImage } from './api/EasterEggApi';
|
||||||
@@ -141,11 +140,8 @@ function App() {
|
|||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (choiceRef?.current?.value && choiceRef.current.value !== "") {
|
if (choiceRef?.current?.value && choiceRef.current.value !== "") {
|
||||||
// TODO: wtf, cos pil, když jsi tohle psal?
|
const locationKey = choiceRef.current.value as LocationKey;
|
||||||
const key = choiceRef?.current?.value;
|
const restaurantKey = Object.keys(Restaurants).indexOf(locationKey);
|
||||||
const locationIndex = Object.keys(Locations).indexOf(key as unknown as Locations);
|
|
||||||
const locationsKey = Object.keys(Locations)[locationIndex];
|
|
||||||
const restaurantKey = Object.keys(Restaurants).indexOf(locationsKey);
|
|
||||||
if (restaurantKey > -1 && food) {
|
if (restaurantKey > -1 && food) {
|
||||||
const restaurant = Object.values(Restaurants)[restaurantKey];
|
const restaurant = Object.values(Restaurants)[restaurantKey];
|
||||||
setFoodChoiceList(food[restaurant]?.food);
|
setFoodChoiceList(food[restaurant]?.food);
|
||||||
@@ -194,9 +190,9 @@ function App() {
|
|||||||
}, [auth?.login, easterEgg?.duration, easterEgg?.url, eggImage]);
|
}, [auth?.login, easterEgg?.duration, easterEgg?.url, eggImage]);
|
||||||
|
|
||||||
const doAddChoice = async (event: React.ChangeEvent<HTMLSelectElement>) => {
|
const doAddChoice = async (event: React.ChangeEvent<HTMLSelectElement>) => {
|
||||||
const index = Object.keys(Locations).indexOf(event.target.value as unknown as Locations);
|
const locationKey = event.target.value as LocationKey;
|
||||||
if (auth?.login) {
|
if (auth?.login) {
|
||||||
await errorHandler(() => addChoice(index, undefined, dayIndex));
|
await errorHandler(() => addChoice(locationKey, undefined, dayIndex));
|
||||||
if (foodChoiceRef.current?.value) {
|
if (foodChoiceRef.current?.value) {
|
||||||
foodChoiceRef.current.value = "";
|
foodChoiceRef.current.value = "";
|
||||||
}
|
}
|
||||||
@@ -211,17 +207,16 @@ function App() {
|
|||||||
|
|
||||||
const doAddFoodChoice = async (event: React.ChangeEvent<HTMLSelectElement>) => {
|
const doAddFoodChoice = async (event: React.ChangeEvent<HTMLSelectElement>) => {
|
||||||
if (event.target.value && foodChoiceList?.length && choiceRef.current?.value) {
|
if (event.target.value && foodChoiceList?.length && choiceRef.current?.value) {
|
||||||
const restaurantKey = choiceRef.current.value;
|
const locationKey = choiceRef.current.value as LocationKey;
|
||||||
if (auth?.login) {
|
if (auth?.login) {
|
||||||
const locationIndex = Object.keys(Locations).indexOf(restaurantKey as unknown as Locations);
|
await errorHandler(() => addChoice(locationKey, Number(event.target.value), dayIndex));
|
||||||
await errorHandler(() => addChoice(locationIndex, Number(event.target.value), dayIndex));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const doRemoveChoices = async (locationKey: string) => {
|
const doRemoveChoices = async (locationKey: LocationKey) => {
|
||||||
if (auth?.login) {
|
if (auth?.login) {
|
||||||
await errorHandler(() => removeChoices(Number(locationKey), dayIndex));
|
await errorHandler(() => removeChoices(locationKey, dayIndex));
|
||||||
// Vyresetujeme výběr, aby bylo jasné pro který případně vybíráme jídlo
|
// Vyresetujeme výběr, aby bylo jasné pro který případně vybíráme jídlo
|
||||||
if (choiceRef?.current?.value) {
|
if (choiceRef?.current?.value) {
|
||||||
choiceRef.current.value = "";
|
choiceRef.current.value = "";
|
||||||
@@ -232,9 +227,9 @@ function App() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const doRemoveFoodChoice = async (locationKey: string, foodIndex: number) => {
|
const doRemoveFoodChoice = async (locationKey: LocationKey, foodIndex: number) => {
|
||||||
if (auth?.login) {
|
if (auth?.login) {
|
||||||
await errorHandler(() => removeChoice(Number(locationKey), foodIndex, dayIndex));
|
await errorHandler(() => removeChoice(locationKey, foodIndex, dayIndex));
|
||||||
if (choiceRef?.current?.value) {
|
if (choiceRef?.current?.value) {
|
||||||
choiceRef.current.value = "";
|
choiceRef.current.value = "";
|
||||||
}
|
}
|
||||||
@@ -355,7 +350,7 @@ function App() {
|
|||||||
} else {
|
} else {
|
||||||
content = <h3>Chyba načtení dat</h3>
|
content = <h3>Chyba načtení dat</h3>
|
||||||
}
|
}
|
||||||
return <Col md={12} lg={6} className='mt-3'>
|
return <Col md={12} lg={3} className='mt-3'>
|
||||||
<h3>{name}</h3>
|
<h3>{name}</h3>
|
||||||
{menu?.lastUpdate && <small>Poslední aktualizace: {getHumanDateTime(new Date(menu.lastUpdate))}</small>}
|
{menu?.lastUpdate && <small>Poslední aktualizace: {getHumanDateTime(new Date(menu.lastUpdate))}</small>}
|
||||||
{content}
|
{content}
|
||||||
@@ -406,8 +401,8 @@ function App() {
|
|||||||
<img src='snowman.png' style={{ position: "absolute", height: "110px", right: 10, top: 5 }} />
|
<img src='snowman.png' style={{ position: "absolute", height: "110px", right: 10, top: 5 }} />
|
||||||
Poslední změny:
|
Poslední změny:
|
||||||
<ul>
|
<ul>
|
||||||
<li>Zimní atmosféra</li>
|
<li>Přidání restaurace Zastávka u Michala</li>
|
||||||
<li>Odstranění podniku U Motlíků</li>
|
<li>Přidání restaurace Pivovarský šenk Šeříková</li>
|
||||||
</ul>
|
</ul>
|
||||||
</Alert>
|
</Alert>
|
||||||
{dayIndex != null &&
|
{dayIndex != null &&
|
||||||
@@ -421,6 +416,8 @@ function App() {
|
|||||||
{food[Restaurants.SLADOVNICKA] && renderFoodTable('Sladovnická', food[Restaurants.SLADOVNICKA])}
|
{food[Restaurants.SLADOVNICKA] && renderFoodTable('Sladovnická', food[Restaurants.SLADOVNICKA])}
|
||||||
{/* {food[Restaurants.UMOTLIKU] && renderFoodTable('U Motlíků', food[Restaurants.UMOTLIKU])} */}
|
{/* {food[Restaurants.UMOTLIKU] && renderFoodTable('U Motlíků', food[Restaurants.UMOTLIKU])} */}
|
||||||
{food[Restaurants.TECHTOWER] && renderFoodTable('TechTower', food[Restaurants.TECHTOWER])}
|
{food[Restaurants.TECHTOWER] && renderFoodTable('TechTower', food[Restaurants.TECHTOWER])}
|
||||||
|
{food[Restaurants.ZASTAVKAUMICHALA] && renderFoodTable('Zastávka u Michala', food[Restaurants.ZASTAVKAUMICHALA])}
|
||||||
|
{food[Restaurants.SENKSERIKOVA] && renderFoodTable('Pivovarský šenk Šeříková', food[Restaurants.SENKSERIKOVA])}
|
||||||
</Row>
|
</Row>
|
||||||
<div className='content-wrapper'>
|
<div className='content-wrapper'>
|
||||||
<div className='content'>
|
<div className='content'>
|
||||||
@@ -430,11 +427,8 @@ function App() {
|
|||||||
<option></option>
|
<option></option>
|
||||||
{Object.entries(Locations)
|
{Object.entries(Locations)
|
||||||
.filter(entry => {
|
.filter(entry => {
|
||||||
// TODO: wtf, cos pil, když jsi tohle psal? v2
|
const locationKey = entry[0] as LocationKey;
|
||||||
const key = entry[0];
|
const restaurantKey = Object.keys(Restaurants).indexOf(locationKey);
|
||||||
const locationIndex = Object.keys(Locations).indexOf(key as unknown as Locations);
|
|
||||||
const locationsKey = Object.keys(Locations)[locationIndex];
|
|
||||||
const restaurantKey = Object.keys(Restaurants).indexOf(locationsKey);
|
|
||||||
const v = Object.values(Restaurants)[restaurantKey];
|
const v = Object.values(Restaurants)[restaurantKey];
|
||||||
return v == null || !food[v]?.closed;
|
return v == null || !food[v]?.closed;
|
||||||
})
|
})
|
||||||
@@ -452,18 +446,25 @@ function App() {
|
|||||||
<p style={{ marginTop: "10px" }}>V kolik hodin preferuješ odchod?</p>
|
<p style={{ marginTop: "10px" }}>V kolik hodin preferuješ odchod?</p>
|
||||||
<Form.Select ref={departureChoiceRef} onChange={handleChangeDepartureTime}>
|
<Form.Select ref={departureChoiceRef} onChange={handleChangeDepartureTime}>
|
||||||
<option></option>
|
<option></option>
|
||||||
{Object.values(DepartureTime).map(time => <option key={time} value={time}>{time}</option>)}
|
{Object.values(DepartureTime)
|
||||||
|
.filter(time => isInTheFuture(time))
|
||||||
|
.map(time => <option key={time} value={time}>{time}</option>)}
|
||||||
</Form.Select>
|
</Form.Select>
|
||||||
</>}
|
</>}
|
||||||
</>}
|
</>}
|
||||||
{Object.keys(data.choices).length > 0 ?
|
{Object.keys(data.choices).length > 0 ?
|
||||||
<Table bordered className='mt-5'>
|
<Table bordered className='mt-5'>
|
||||||
<tbody>
|
<tbody>
|
||||||
{Object.keys(data.choices).map((locationKey: string) => {
|
{Object.keys(data.choices).map(key => {
|
||||||
const locationName = Object.values(Locations)[Number(locationKey)];
|
const locationKey = key as LocationKey;
|
||||||
const locationLoginList = Object.entries(data.choices[Number(locationKey)]);
|
const locationName = Locations[locationKey];
|
||||||
|
const loginObject = data.choices[locationKey];
|
||||||
|
if (!loginObject) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const locationLoginList = Object.entries(loginObject);
|
||||||
return (
|
return (
|
||||||
<tr key={locationKey}>
|
<tr key={key}>
|
||||||
<td>{locationName}</td>
|
<td>{locationName}</td>
|
||||||
<td className='p-0'>
|
<td className='p-0'>
|
||||||
<Table>
|
<Table>
|
||||||
@@ -485,20 +486,20 @@ function App() {
|
|||||||
setNoteModalOpen(true);
|
setNoteModalOpen(true);
|
||||||
}} title='Upravit poznámku' className='action-icon' icon={faNoteSticky} />}
|
}} title='Upravit poznámku' className='action-icon' icon={faNoteSticky} />}
|
||||||
{login === auth.login && canChangeChoice && <FontAwesomeIcon onClick={() => {
|
{login === auth.login && canChangeChoice && <FontAwesomeIcon onClick={() => {
|
||||||
doRemoveChoices(locationKey);
|
doRemoveChoices(key as LocationKey);
|
||||||
}} title={`Odstranit volbu ${locationName}, včetně případných zvolených jídel`} className='action-icon' icon={faTrashCan} />}
|
}} title={`Odstranit volbu ${locationName}, včetně případných zvolených jídel`} className='action-icon' icon={faTrashCan} />}
|
||||||
</td>
|
</td>
|
||||||
{userChoices?.length && food ? <td>
|
{userChoices?.length && food ? <td>
|
||||||
<ul>
|
<ul>
|
||||||
{userChoices?.map(foodIndex => {
|
{userChoices?.map(foodIndex => {
|
||||||
const locationsKey = Object.keys(Locations)[Number(locationKey)]
|
// TODO narovnat, tohle je zbytečně složité
|
||||||
const restaurantKey = Object.keys(Restaurants).indexOf(locationsKey);
|
const restaurantKey = Object.keys(Restaurants).indexOf(key);
|
||||||
const restaurant = Object.values(Restaurants)[restaurantKey];
|
const restaurant = Object.values(Restaurants)[restaurantKey];
|
||||||
const foodName = food[restaurant]?.food[foodIndex].name;
|
const foodName = food[restaurant]?.food[foodIndex].name;
|
||||||
return <li key={foodIndex}>
|
return <li key={foodIndex}>
|
||||||
{foodName}
|
{foodName}
|
||||||
{login === auth.login && canChangeChoice && <FontAwesomeIcon onClick={() => {
|
{login === auth.login && canChangeChoice && <FontAwesomeIcon onClick={() => {
|
||||||
doRemoveFoodChoice(locationKey, foodIndex);
|
doRemoveFoodChoice(key as LocationKey, foodIndex);
|
||||||
}} title={`Odstranit ${foodName}`} className='action-icon' icon={faTrashCan} />}
|
}} title={`Odstranit ${foodName}`} className='action-icon' icon={faTrashCan} />}
|
||||||
</li>
|
</li>
|
||||||
})}
|
})}
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
import {DepartureTime} from "../../types";
|
||||||
|
|
||||||
const TOKEN_KEY = "token";
|
const TOKEN_KEY = "token";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -43,3 +45,20 @@ export function getHumanDateTime(datetime: Date) {
|
|||||||
return `${day}.${month}.${year} ${hours}:${minutes}`;
|
return `${day}.${month}.${year} ${hours}:${minutes}`;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Vrátí true, pokud je předaný čas větší než aktuální čas.
|
||||||
|
*/
|
||||||
|
export function isInTheFuture(time: DepartureTime) {
|
||||||
|
const now = new Date();
|
||||||
|
const currentHours = now.getHours();
|
||||||
|
const currentMinutes = now.getMinutes();
|
||||||
|
const currentDate = now.toDateString();
|
||||||
|
const [hours, minutes] = time.split(':').map(Number);
|
||||||
|
|
||||||
|
if (currentDate === now.toDateString()) {
|
||||||
|
return hours > currentHours || (hours === currentHours && minutes > currentMinutes);
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { EasterEgg } from "../types";
|
import { EasterEgg } from "../../../types";
|
||||||
import { api } from "./Api";
|
import { api } from "./Api";
|
||||||
|
|
||||||
const EASTER_EGGS_API_PREFIX = '/api/easterEggs';
|
const EASTER_EGGS_API_PREFIX = '/api/easterEggs';
|
||||||
|
|||||||
@@ -1,18 +1,18 @@
|
|||||||
import { AddChoiceRequest, ChangeDepartureTimeRequest, RemoveChoiceRequest, RemoveChoicesRequest, UpdateNoteRequest } from "../types";
|
import { AddChoiceRequest, ChangeDepartureTimeRequest, LocationKey, RemoveChoiceRequest, RemoveChoicesRequest, UpdateNoteRequest } from "../../../types";
|
||||||
import { api } from "./Api";
|
import { api } from "./Api";
|
||||||
|
|
||||||
const FOOD_API_PREFIX = '/api/food';
|
const FOOD_API_PREFIX = '/api/food';
|
||||||
|
|
||||||
export const addChoice = async (locationIndex: number, foodIndex?: number, dayIndex?: number) => {
|
export const addChoice = async (locationKey: LocationKey, foodIndex?: number, dayIndex?: number) => {
|
||||||
return await api.post<AddChoiceRequest, void>(`${FOOD_API_PREFIX}/addChoice`, { locationIndex, foodIndex, dayIndex });
|
return await api.post<AddChoiceRequest, void>(`${FOOD_API_PREFIX}/addChoice`, { locationKey, foodIndex, dayIndex });
|
||||||
}
|
}
|
||||||
|
|
||||||
export const removeChoices = async (locationIndex: number, dayIndex?: number) => {
|
export const removeChoices = async (locationKey: LocationKey, dayIndex?: number) => {
|
||||||
return await api.post<RemoveChoicesRequest, void>(`${FOOD_API_PREFIX}/removeChoices`, { locationIndex, dayIndex });
|
return await api.post<RemoveChoicesRequest, void>(`${FOOD_API_PREFIX}/removeChoices`, { locationKey, dayIndex });
|
||||||
}
|
}
|
||||||
|
|
||||||
export const removeChoice = async (locationIndex: number, foodIndex: number, dayIndex?: number) => {
|
export const removeChoice = async (locationKey: LocationKey, foodIndex: number, dayIndex?: number) => {
|
||||||
return await api.post<RemoveChoiceRequest, void>(`${FOOD_API_PREFIX}/removeChoice`, { locationIndex, foodIndex, dayIndex });
|
return await api.post<RemoveChoiceRequest, void>(`${FOOD_API_PREFIX}/removeChoice`, { locationKey, foodIndex, dayIndex });
|
||||||
}
|
}
|
||||||
|
|
||||||
export const updateNote = async (note?: string, dayIndex?: number) => {
|
export const updateNote = async (note?: string, dayIndex?: number) => {
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { AddPizzaRequest, FinishDeliveryRequest, PizzaOrder, RemovePizzaRequest, UpdatePizzaDayNoteRequest, UpdatePizzaFeeRequest } from "../types";
|
import { AddPizzaRequest, FinishDeliveryRequest, PizzaOrder, RemovePizzaRequest, UpdatePizzaDayNoteRequest, UpdatePizzaFeeRequest } from "../../../types";
|
||||||
import { api } from "./Api";
|
import { api } from "./Api";
|
||||||
|
|
||||||
const PIZZADAY_API_PREFIX = '/api/pizzaDay';
|
const PIZZADAY_API_PREFIX = '/api/pizzaDay';
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { FeatureRequest, UpdateFeatureVoteRequest } from "../types";
|
import { FeatureRequest, UpdateFeatureVoteRequest } from "../../../types";
|
||||||
import { api } from "./Api";
|
import { api } from "./Api";
|
||||||
|
|
||||||
const VOTING_API_PREFIX = '/api/voting';
|
const VOTING_API_PREFIX = '/api/voting';
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import { useAuth } from "../context/auth";
|
|||||||
import SettingsModal from "./modals/SettingsModal";
|
import SettingsModal from "./modals/SettingsModal";
|
||||||
import { useSettings } from "../context/settings";
|
import { useSettings } from "../context/settings";
|
||||||
import FeaturesVotingModal from "./modals/FeaturesVotingModal";
|
import FeaturesVotingModal from "./modals/FeaturesVotingModal";
|
||||||
import { FeatureRequest } from "../types";
|
import { FeatureRequest } from "../../../types";
|
||||||
import { errorHandler } from "../api/Api";
|
import { errorHandler } from "../api/Api";
|
||||||
import { getFeatureVotes, updateFeatureVote } from "../api/VotingApi";
|
import { getFeatureVotes, updateFeatureVote } from "../api/VotingApi";
|
||||||
import PizzaCalculatorModal from "./modals/PizzaCalculatorModal";
|
import PizzaCalculatorModal from "./modals/PizzaCalculatorModal";
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import { Table } from "react-bootstrap";
|
import { Table } from "react-bootstrap";
|
||||||
import { Order, PizzaDayState, PizzaOrder } from "../types";
|
import { Order, PizzaDayState, PizzaOrder } from "../../../types";
|
||||||
import PizzaOrderRow from "./PizzaOrderRow";
|
import PizzaOrderRow from "./PizzaOrderRow";
|
||||||
import { updatePizzaFee } from "../api/PizzaDayApi";
|
import { updatePizzaFee } from "../api/PizzaDayApi";
|
||||||
|
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ import React, { useState } from "react";
|
|||||||
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
|
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
|
||||||
import { faMoneyBill1, faTrashCan } from "@fortawesome/free-regular-svg-icons";
|
import { faMoneyBill1, faTrashCan } from "@fortawesome/free-regular-svg-icons";
|
||||||
import { useAuth } from "../context/auth";
|
import { useAuth } from "../context/auth";
|
||||||
import { Order, PizzaDayState, PizzaOrder } from "../types";
|
import { Order, PizzaDayState, PizzaOrder } from "../../../types";
|
||||||
import PizzaAdditionalFeeModal from "./modals/PizzaAdditionalFeeModal";
|
import PizzaAdditionalFeeModal from "./modals/PizzaAdditionalFeeModal";
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import { Modal, Button, Form } from "react-bootstrap"
|
import { Modal, Button, Form } from "react-bootstrap"
|
||||||
import { FeatureRequest } from "../../types";
|
import { FeatureRequest } from "../../../../types";
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
isOpen: boolean,
|
isOpen: boolean,
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import { useEffect, useState } from "react";
|
import { useEffect, useState } from "react";
|
||||||
import { getEasterEgg } from "../api/EasterEggApi";
|
import { getEasterEgg } from "../api/EasterEggApi";
|
||||||
import { AuthContextProps } from "./auth";
|
import { AuthContextProps } from "./auth";
|
||||||
import { EasterEgg } from "../types";
|
import { EasterEgg } from "../../../types";
|
||||||
|
|
||||||
export const useEasterEgg = (auth?: AuthContextProps | null): [EasterEgg | undefined, boolean] => {
|
export const useEasterEgg = (auth?: AuthContextProps | null): [EasterEgg | undefined, boolean] => {
|
||||||
const [result, setResult] = useState<EasterEgg | undefined>();
|
const [result, setResult] = useState<EasterEgg | undefined>();
|
||||||
|
|||||||
@@ -427,7 +427,181 @@ const MOCK_DATA = {
|
|||||||
isSoup: false,
|
isSoup: false,
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
]
|
],
|
||||||
|
'zastavkaUmichala': [
|
||||||
|
[
|
||||||
|
{
|
||||||
|
amount: "-",
|
||||||
|
name: "Fazolačka s klobásou & zakysačkou",
|
||||||
|
price: "39\xA0Kč",
|
||||||
|
isSoup: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
amount: "-",
|
||||||
|
name: "Zeleninová musaka – lilek, cuketa, tomatové sugo & sýrový bešamel",
|
||||||
|
price: "135\xA0Kč",
|
||||||
|
isSoup: false,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
amount: "-",
|
||||||
|
name: "Slovácké strapačky s uzenou slaninou, zelím, mletým pepřem & sekanou petrželkou",
|
||||||
|
price: "140\xA0Kč",
|
||||||
|
isSoup: false,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
amount: "-",
|
||||||
|
name: "Hovězí guláš s vejcem, zeleninovou garniturkou & žemlovými knedlíky",
|
||||||
|
price: "145\xA0Kč",
|
||||||
|
isSoup: false,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
amount: "-",
|
||||||
|
name: "Kuřecí roláda s kaštanovou nádivkou, demi-glace & smetanovou bramborovou kaší",
|
||||||
|
price: "150\xA0Kč",
|
||||||
|
isSoup: false,
|
||||||
|
}
|
||||||
|
],
|
||||||
|
[
|
||||||
|
{
|
||||||
|
amount: "-",
|
||||||
|
name: "Hovězí vývar se zeleninou a játrovou rýží",
|
||||||
|
price: "39\xA0Kč",
|
||||||
|
isSoup: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
amount: "-",
|
||||||
|
name: "Pečené vepřové koleno, křen, hořčice, chléb",
|
||||||
|
price: "320\xA0Kč",
|
||||||
|
isSoup: false,
|
||||||
|
}
|
||||||
|
],
|
||||||
|
[
|
||||||
|
{
|
||||||
|
amount: "-",
|
||||||
|
name: "Zeleninová polévka s kuskusem",
|
||||||
|
price: "39\xA0Kč",
|
||||||
|
isSoup: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
amount: "-",
|
||||||
|
name: "Poutine (trhané vepřové, hranolky, sýr, čalamáda, pikantní omáčka)",
|
||||||
|
price: "190\xA0Kč",
|
||||||
|
isSoup: false,
|
||||||
|
}
|
||||||
|
],
|
||||||
|
[
|
||||||
|
{
|
||||||
|
amount: "-",
|
||||||
|
name: "Hrachová polévka s uzeninou",
|
||||||
|
price: "39\xA0Kč",
|
||||||
|
isSoup: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
amount: "-",
|
||||||
|
name: "Vepřový řízek z kotlety, domácí bramborový salát",
|
||||||
|
price: "170\xA0Kč",
|
||||||
|
isSoup: false,
|
||||||
|
}
|
||||||
|
],
|
||||||
|
[
|
||||||
|
{
|
||||||
|
amount: "-",
|
||||||
|
name: "Cibulačka se sýrem",
|
||||||
|
price: "39\xA0Kč",
|
||||||
|
isSoup: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
amount: "-",
|
||||||
|
name: "Burger z Chuck rollu, hranolky, tatarská omáčka",
|
||||||
|
price: "200\xA0Kč",
|
||||||
|
isSoup: false,
|
||||||
|
}
|
||||||
|
],
|
||||||
|
],
|
||||||
|
'senkSerikova': [
|
||||||
|
[
|
||||||
|
{
|
||||||
|
amount: "-",
|
||||||
|
name: "Drůbeží vývar s masem a nudlemi",
|
||||||
|
price: "45\xA0Kč",
|
||||||
|
isSoup: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
amount: "-",
|
||||||
|
name: "Vepřová pečeně se zelím a houskovým knedlíkem",
|
||||||
|
price: "155\xA0Kč",
|
||||||
|
isSoup: false,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
amount: "-",
|
||||||
|
name: "Špagety s kuřecím masem, špenátem a smetanou",
|
||||||
|
price: "145\xA0Kč",
|
||||||
|
isSoup: false,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
amount: "-",
|
||||||
|
name: "Medailonky z vepřové panenky s fazolkami se slaninou, šťouchané brambory",
|
||||||
|
price: "185\xA0Kč",
|
||||||
|
isSoup: false,
|
||||||
|
}
|
||||||
|
],
|
||||||
|
[
|
||||||
|
{
|
||||||
|
amount: "-",
|
||||||
|
name: "Mrkvová polévka se zázvorem a kokosovým mlékem",
|
||||||
|
price: "45\xA0Kč",
|
||||||
|
isSoup: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
amount: "-",
|
||||||
|
name: "Hovězí po Burgundsku, bramborová kaše",
|
||||||
|
price: "155\xA0Kč",
|
||||||
|
isSoup: false,
|
||||||
|
}
|
||||||
|
],
|
||||||
|
[
|
||||||
|
{
|
||||||
|
amount: "-",
|
||||||
|
name: "Hovězí vývar s játrovými knedlíčky",
|
||||||
|
price: "45\xA0Kč",
|
||||||
|
isSoup: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
amount: "-",
|
||||||
|
name: "Kuřecí plátky na sušených rajčatech, bylinkách a česneku, bramborová kaše",
|
||||||
|
price: "155\xA0Kč",
|
||||||
|
isSoup: false,
|
||||||
|
}
|
||||||
|
],
|
||||||
|
[
|
||||||
|
{
|
||||||
|
amount: "-",
|
||||||
|
name: "Kuřecí vývar s rýží",
|
||||||
|
price: "45\xA0Kč",
|
||||||
|
isSoup: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
amount: "-",
|
||||||
|
name: "Rajská s plněnou paprikou, knedlík",
|
||||||
|
price: "170\xA0Kč",
|
||||||
|
isSoup: false,
|
||||||
|
}
|
||||||
|
],
|
||||||
|
[
|
||||||
|
{
|
||||||
|
amount: "-",
|
||||||
|
name: "Mexická fazolová polévka",
|
||||||
|
price: "45\xA0Kč",
|
||||||
|
isSoup: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
amount: "-",
|
||||||
|
name: "Ragú z trhané kachny, onsen vejce, soté ze špenátu a ředkvičky, bramborové pyré, lanýžová sůl, zelený olej",
|
||||||
|
price: "189\xA0Kč",
|
||||||
|
isSoup: false,
|
||||||
|
}
|
||||||
|
],
|
||||||
|
],
|
||||||
}
|
}
|
||||||
|
|
||||||
// Mockovací data pro Pizza day
|
// Mockovací data pro Pizza day
|
||||||
@@ -1180,8 +1354,11 @@ const MOCK_PIZZA_LIST = [
|
|||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|
||||||
export const getTodayMock = () => {
|
/**
|
||||||
return '2023-05-31'; // středa
|
* Funkce vrací mock datu ve formátu YYYY-MM-DD
|
||||||
|
*/
|
||||||
|
export const getTodayMock = (): Date => {
|
||||||
|
return new Date('2025-01-10'); // pátek
|
||||||
}
|
}
|
||||||
|
|
||||||
export const getMenuSladovnickaMock = () => {
|
export const getMenuSladovnickaMock = () => {
|
||||||
@@ -1196,6 +1373,14 @@ export const getMenuTechTowerMock = () => {
|
|||||||
return MOCK_DATA['techTower'];
|
return MOCK_DATA['techTower'];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export const getMenuZastavkaUmichalaMock = () => {
|
||||||
|
return MOCK_DATA['zastavkaUmichala'];
|
||||||
|
}
|
||||||
|
|
||||||
|
export const getMenuSenkSerikovaMock = () => {
|
||||||
|
return MOCK_DATA['senkSerikova'];
|
||||||
|
}
|
||||||
|
|
||||||
export const getPizzaListMock = () => {
|
export const getPizzaListMock = () => {
|
||||||
return MOCK_PIZZA_LIST;
|
return MOCK_PIZZA_LIST;
|
||||||
}
|
}
|
||||||
@@ -1,7 +1,8 @@
|
|||||||
import axios from "axios";
|
import axios from "axios";
|
||||||
import { load } from 'cheerio';
|
import { load } from 'cheerio';
|
||||||
import { Food } from "../../types";
|
import { Food } from "../../types";
|
||||||
import { getMenuSladovnickaMock, getMenuTechTowerMock, getMenuUMotlikuMock } from "./mock";
|
import {getMenuSladovnickaMock, getMenuTechTowerMock, getMenuUMotlikuMock, getMenuZastavkaUmichalaMock, getMenuSenkSerikovaMock} from "./mock";
|
||||||
|
import {formatDate} from "./utils";
|
||||||
|
|
||||||
// Fráze v názvech jídel, které naznačují že se jedná o polévku
|
// Fráze v názvech jídel, které naznačují že se jedná o polévku
|
||||||
const SOUP_NAMES = [
|
const SOUP_NAMES = [
|
||||||
@@ -25,6 +26,8 @@ const DAYS_IN_WEEK = ['pondělí', 'úterý', 'středa', 'čtvrtek', 'pátek', '
|
|||||||
const SLADOVNICKA_URL = 'https://sladovnicka.unasplzenchutna.cz/cz/denni-nabidka';
|
const SLADOVNICKA_URL = 'https://sladovnicka.unasplzenchutna.cz/cz/denni-nabidka';
|
||||||
const U_MOTLIKU_URL = 'https://www.umotliku.cz/menu';
|
const U_MOTLIKU_URL = 'https://www.umotliku.cz/menu';
|
||||||
const TECHTOWER_URL = 'https://www.equifarm.cz/restaurace-techtower';
|
const TECHTOWER_URL = 'https://www.equifarm.cz/restaurace-techtower';
|
||||||
|
const ZASTAVKAUMICHALA_URL = 'https://www.zastavkaumichala.cz';
|
||||||
|
const SENKSERIKOVA_URL = 'https://www.menicka.cz/6561-pivovarsky-senk-serikova.html';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Vrátí true, pokud předaný text obsahuje některé ze slov, které naznačuje, že se jedná o polévku.
|
* Vrátí true, pokud předaný text obsahuje některé ze slov, které naznačuje, že se jedná o polévku.
|
||||||
@@ -327,3 +330,105 @@ export const getMenuTechTower = async (firstDayOfWeek: Date, mock: boolean = fal
|
|||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Získá obědovou nabídku ZastavkaUmichala pro jeden týden.
|
||||||
|
*
|
||||||
|
* @param firstDayOfWeek první den v týdnu, pro který získat menu
|
||||||
|
* @param mock zda vrátit mock data
|
||||||
|
* @returns seznam jídel pro dané datum
|
||||||
|
*/
|
||||||
|
export const getMenuZastavkaUmichala = async (firstDayOfWeek: Date, mock: boolean = false): Promise<Food[][]> => {
|
||||||
|
if (mock) {
|
||||||
|
return getMenuZastavkaUmichalaMock();
|
||||||
|
}
|
||||||
|
|
||||||
|
const nowDate = new Date().getDate();
|
||||||
|
const headers = {
|
||||||
|
"Cookie": "_nss=1; PHPSESSID=9e37de17e0326b0942613d6e67a30e69",
|
||||||
|
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/132.0.0.0 Safari/537.36",
|
||||||
|
};
|
||||||
|
const result: Food[][] = [];
|
||||||
|
for (let dayIndex = 0; dayIndex < 5; dayIndex++) {
|
||||||
|
const currentDate = new Date(firstDayOfWeek);
|
||||||
|
currentDate.setDate(firstDayOfWeek.getDate() + dayIndex);
|
||||||
|
|
||||||
|
if (currentDate.getDate() < nowDate || (currentDate.getDate() === nowDate && new Date().getHours() >= 14)) {
|
||||||
|
result[dayIndex] = [{
|
||||||
|
amount: undefined,
|
||||||
|
name: "Pro tento den není uveřejněna nabídka jídel",
|
||||||
|
price: "",
|
||||||
|
isSoup: false,
|
||||||
|
}];
|
||||||
|
continue;
|
||||||
|
} else {
|
||||||
|
const url = (currentDate.getDate() === nowDate) ?
|
||||||
|
ZASTAVKAUMICHALA_URL : ZASTAVKAUMICHALA_URL + '/?do=dailyMenu-changeDate&dailyMenu-dateString=' + formatDate(currentDate, 'DD.MM.YYYY');
|
||||||
|
const html = await axios.get(url, {
|
||||||
|
headers,
|
||||||
|
}).then(res => res.data).then(content => content);
|
||||||
|
const $ = load(html);
|
||||||
|
|
||||||
|
const currentDayFood: Food[] = [];
|
||||||
|
$('.foodsList li').each((index, element) => {
|
||||||
|
currentDayFood.push({
|
||||||
|
amount: '-',
|
||||||
|
name: sanitizeText($(element).contents().not('span').text()),
|
||||||
|
price: sanitizeText($(element).find('span').text()),
|
||||||
|
isSoup: (index === 0),
|
||||||
|
});
|
||||||
|
});
|
||||||
|
result[dayIndex] = currentDayFood;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Získá obědovou nabídku SenkSerikova pro jeden týden.
|
||||||
|
*
|
||||||
|
* @param firstDayOfWeek první den v týdnu, pro který získat menu
|
||||||
|
* @param mock zda vrátit mock data
|
||||||
|
* @returns seznam jídel pro dané datum
|
||||||
|
*/
|
||||||
|
export const getMenuSenkSerikova = async (firstDayOfWeek: Date, mock: boolean = false): Promise<Food[][]> => {
|
||||||
|
if (mock) {
|
||||||
|
return getMenuSenkSerikovaMock();
|
||||||
|
}
|
||||||
|
|
||||||
|
const decoder = new TextDecoder('windows-1250');
|
||||||
|
const html = await axios.get(SENKSERIKOVA_URL, {
|
||||||
|
responseType: 'arraybuffer',
|
||||||
|
responseEncoding: 'binary'
|
||||||
|
}).then(res => decoder.decode(new Uint8Array(res.data))).then(content => content);
|
||||||
|
const $ = load(html);
|
||||||
|
|
||||||
|
const nowDate = new Date().getDate();
|
||||||
|
const currentDate = new Date(firstDayOfWeek);
|
||||||
|
const result: Food[][] = [];
|
||||||
|
let dayIndex = 0;
|
||||||
|
while(currentDate.getDate() < nowDate) {
|
||||||
|
result[dayIndex] = [{
|
||||||
|
amount: undefined,
|
||||||
|
name: "Pro tento den není uveřejněna nabídka jídel",
|
||||||
|
price: "",
|
||||||
|
isSoup: false,
|
||||||
|
}];
|
||||||
|
dayIndex = dayIndex + 1;
|
||||||
|
currentDate.setDate(firstDayOfWeek.getDate() + dayIndex);
|
||||||
|
}
|
||||||
|
|
||||||
|
$('.menicka').each((i, element) => {
|
||||||
|
const currentDayFood: Food[] = [];
|
||||||
|
$(element).find('.popup-gallery li').each((j, element) => {
|
||||||
|
currentDayFood.push({
|
||||||
|
amount: '-',
|
||||||
|
name: $(element).children('div.polozka').text(),
|
||||||
|
price: $(element).children('div.cena').text().replace(/ /g, '\xA0'),
|
||||||
|
isSoup: $(element).hasClass('polevka'),
|
||||||
|
});
|
||||||
|
});
|
||||||
|
result[dayIndex++] = currentDayFood;
|
||||||
|
});
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|||||||
@@ -33,7 +33,6 @@ const router = express.Router();
|
|||||||
router.post("/addChoice", async (req: Request<{}, any, AddChoiceRequest>, res, next) => {
|
router.post("/addChoice", async (req: Request<{}, any, AddChoiceRequest>, res, next) => {
|
||||||
const login = getLogin(parseToken(req));
|
const login = getLogin(parseToken(req));
|
||||||
const trusted = getTrusted(parseToken(req));
|
const trusted = getTrusted(parseToken(req));
|
||||||
if (req.body.locationIndex > -1) {
|
|
||||||
let date = undefined;
|
let date = undefined;
|
||||||
if (req.body.dayIndex != null) {
|
if (req.body.dayIndex != null) {
|
||||||
let dayIndex;
|
let dayIndex;
|
||||||
@@ -45,12 +44,10 @@ router.post("/addChoice", async (req: Request<{}, any, AddChoiceRequest>, res, n
|
|||||||
date = getDateForWeekIndex(dayIndex);
|
date = getDateForWeekIndex(dayIndex);
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
const data = await addChoice(login, trusted, req.body.locationIndex, req.body.foodIndex, date);
|
const data = await addChoice(login, trusted, req.body.locationKey, req.body.foodIndex, date);
|
||||||
getWebsocket().emit("message", await addVolatileData(data));
|
getWebsocket().emit("message", await addVolatileData(data));
|
||||||
return res.status(200).json(data);
|
return res.status(200).json(data);
|
||||||
} catch (e: any) { next(e) }
|
} catch (e: any) { next(e) }
|
||||||
}
|
|
||||||
return res.status(400); // TODO přidat popis chyby
|
|
||||||
});
|
});
|
||||||
|
|
||||||
router.post("/removeChoices", async (req: Request<{}, any, RemoveChoicesRequest>, res, next) => {
|
router.post("/removeChoices", async (req: Request<{}, any, RemoveChoicesRequest>, res, next) => {
|
||||||
@@ -67,7 +64,7 @@ router.post("/removeChoices", async (req: Request<{}, any, RemoveChoicesRequest>
|
|||||||
date = getDateForWeekIndex(dayIndex);
|
date = getDateForWeekIndex(dayIndex);
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
const data = await removeChoices(login, trusted, req.body.locationIndex, date);
|
const data = await removeChoices(login, trusted, req.body.locationKey, date);
|
||||||
getWebsocket().emit("message", await addVolatileData(data));
|
getWebsocket().emit("message", await addVolatileData(data));
|
||||||
res.status(200).json(data);
|
res.status(200).json(data);
|
||||||
} catch (e: any) { next(e) }
|
} catch (e: any) { next(e) }
|
||||||
@@ -87,7 +84,7 @@ router.post("/removeChoice", async (req: Request<{}, any, RemoveChoiceRequest>,
|
|||||||
date = getDateForWeekIndex(dayIndex);
|
date = getDateForWeekIndex(dayIndex);
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
const data = await removeChoice(login, trusted, req.body.locationIndex, req.body.foodIndex, date);
|
const data = await removeChoice(login, trusted, req.body.locationKey, req.body.foodIndex, date);
|
||||||
getWebsocket().emit("message", await addVolatileData(data));
|
getWebsocket().emit("message", await addVolatileData(data));
|
||||||
res.status(200).json(data);
|
res.status(200).json(data);
|
||||||
} catch (e: any) { next(e) }
|
} catch (e: any) { next(e) }
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import { InsufficientPermissions, formatDate, getDayOfWeekIndex, getFirstWorkDayOfWeek, getHumanDate, getHumanTime, getIsWeekend, getLastWorkDayOfWeek, getWeekNumber } from "./utils";
|
import { InsufficientPermissions, formatDate, getDayOfWeekIndex, getFirstWorkDayOfWeek, getHumanDate, getIsWeekend, getWeekNumber } from "./utils";
|
||||||
import { ClientData, Locations, Restaurants, DayMenu, DepartureTime, DayData, WeekMenu } from "../../types";
|
import { ClientData, Restaurants, DayMenu, DepartureTime, DayData, WeekMenu, LocationKey } from "../../types";
|
||||||
import getStorage from "./storage";
|
import getStorage from "./storage";
|
||||||
import { getMenuSladovnicka, getMenuTechTower, getMenuUMotliku } from "./restaurants";
|
import { getMenuSladovnicka, getMenuTechTower, getMenuUMotliku, getMenuZastavkaUmichala, getMenuSenkSerikova } from "./restaurants";
|
||||||
import { getTodayMock } from "./mock";
|
import { getTodayMock } from "./mock";
|
||||||
|
|
||||||
const storage = getStorage();
|
const storage = getStorage();
|
||||||
@@ -10,7 +10,7 @@ const MENU_PREFIX = 'menu';
|
|||||||
/** Vrátí dnešní datum, případně fiktivní datum pro účely vývoje a testování. */
|
/** Vrátí dnešní datum, případně fiktivní datum pro účely vývoje a testování. */
|
||||||
export function getToday(): Date {
|
export function getToday(): Date {
|
||||||
if (process.env.MOCK_DATA === 'true') {
|
if (process.env.MOCK_DATA === 'true') {
|
||||||
return new Date(getTodayMock());
|
return getTodayMock();
|
||||||
}
|
}
|
||||||
return new Date();
|
return new Date();
|
||||||
}
|
}
|
||||||
@@ -61,6 +61,8 @@ export async function getData(date?: Date): Promise<ClientData> {
|
|||||||
[Restaurants.SLADOVNICKA]: await getRestaurantMenu(Restaurants.SLADOVNICKA, date),
|
[Restaurants.SLADOVNICKA]: await getRestaurantMenu(Restaurants.SLADOVNICKA, date),
|
||||||
// [Restaurants.UMOTLIKU]: await getRestaurantMenu(Restaurants.UMOTLIKU, date),
|
// [Restaurants.UMOTLIKU]: await getRestaurantMenu(Restaurants.UMOTLIKU, date),
|
||||||
[Restaurants.TECHTOWER]: await getRestaurantMenu(Restaurants.TECHTOWER, date),
|
[Restaurants.TECHTOWER]: await getRestaurantMenu(Restaurants.TECHTOWER, date),
|
||||||
|
[Restaurants.ZASTAVKAUMICHALA]: await getRestaurantMenu(Restaurants.ZASTAVKAUMICHALA, date),
|
||||||
|
[Restaurants.SENKSERIKOVA]: await getRestaurantMenu(Restaurants.SENKSERIKOVA, date),
|
||||||
}
|
}
|
||||||
clientData = await addVolatileData(clientData);
|
clientData = await addVolatileData(clientData);
|
||||||
return clientData;
|
return clientData;
|
||||||
@@ -168,6 +170,32 @@ export async function getRestaurantMenu(restaurant: Restaurants, date?: Date): P
|
|||||||
} catch (e: any) {
|
} catch (e: any) {
|
||||||
console.error("Selhalo načtení jídel pro podnik TechTower", e);
|
console.error("Selhalo načtení jídel pro podnik TechTower", e);
|
||||||
}
|
}
|
||||||
|
case Restaurants.ZASTAVKAUMICHALA:
|
||||||
|
try {
|
||||||
|
const zastavkaUmichalaFood = await getMenuZastavkaUmichala(firstDay, mock);
|
||||||
|
for (let i = 0; i < zastavkaUmichalaFood.length; i++) {
|
||||||
|
menus[i][restaurant]!.food = zastavkaUmichalaFood[i];
|
||||||
|
if (zastavkaUmichalaFood[i]?.length === 1 && zastavkaUmichalaFood[i][0].name === 'Pro tento den není uveřejněna nabídka jídel.') {
|
||||||
|
menus[i][restaurant]!.closed = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
} catch (e: any) {
|
||||||
|
console.error("Selhalo načtení jídel pro podnik Zastávka u Michala", e);
|
||||||
|
}
|
||||||
|
case Restaurants.SENKSERIKOVA:
|
||||||
|
try {
|
||||||
|
const senkSerikovaFood = await getMenuSenkSerikova(firstDay, mock);
|
||||||
|
for (let i = 0; i < senkSerikovaFood.length; i++) {
|
||||||
|
menus[i][restaurant]!.food = senkSerikovaFood[i];
|
||||||
|
if (senkSerikovaFood[i]?.length === 1 && senkSerikovaFood[i][0].name === 'Pro tento den nebylo zadáno menu.') {
|
||||||
|
menus[i][restaurant]!.closed = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
} catch (e: any) {
|
||||||
|
console.error("Selhalo načtení jídel pro podnik Pivovarský šenk Šeříková", e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
await storage.setData(getMenuKey(usedDate), menus);
|
await storage.setData(getMenuKey(usedDate), menus);
|
||||||
}
|
}
|
||||||
@@ -192,19 +220,19 @@ export async function initIfNeeded(date?: Date) {
|
|||||||
*
|
*
|
||||||
* @param login login uživatele
|
* @param login login uživatele
|
||||||
* @param trusted příznak, zda se jedná o ověřeného uživatele
|
* @param trusted příznak, zda se jedná o ověřeného uživatele
|
||||||
* @param locationIndex vybrané "umístění"
|
* @param locationKey vybrané "umístění"
|
||||||
* @param date datum, ke kterému se volba vztahuje
|
* @param date datum, ke kterému se volba vztahuje
|
||||||
* @returns
|
* @returns
|
||||||
*/
|
*/
|
||||||
export async function removeChoices(login: string, trusted: boolean, locationIndex: number, date?: Date) {
|
export async function removeChoices(login: string, trusted: boolean, locationKey: LocationKey, date?: Date) {
|
||||||
const selectedDay = formatDate(date ?? getToday());
|
const selectedDay = formatDate(date ?? getToday());
|
||||||
let data: DayData = await storage.getData(selectedDay);
|
let data: DayData = await storage.getData(selectedDay);
|
||||||
validateTrusted(data, login, trusted);
|
validateTrusted(data, login, trusted);
|
||||||
if (locationIndex in data.choices) {
|
if (locationKey in data.choices) {
|
||||||
if (login in data.choices[locationIndex]) {
|
if (data.choices[locationKey] && login in data.choices[locationKey]) {
|
||||||
delete data.choices[locationIndex][login]
|
delete data.choices[locationKey][login]
|
||||||
if (Object.keys(data.choices[locationIndex]).length === 0) {
|
if (Object.keys(data.choices[locationKey]).length === 0) {
|
||||||
delete data.choices[locationIndex]
|
delete data.choices[locationKey]
|
||||||
}
|
}
|
||||||
await storage.setData(selectedDay, data);
|
await storage.setData(selectedDay, data);
|
||||||
}
|
}
|
||||||
@@ -218,20 +246,20 @@ export async function removeChoices(login: string, trusted: boolean, locationInd
|
|||||||
*
|
*
|
||||||
* @param login login uživatele
|
* @param login login uživatele
|
||||||
* @param trusted příznak, zda se jedná o ověřeného uživatele
|
* @param trusted příznak, zda se jedná o ověřeného uživatele
|
||||||
* @param locationIndex vybrané "umístění"
|
* @param locationKey vybrané "umístění"
|
||||||
* @param foodIndex index jídla v jídelním lístku daného umístění, pokud existuje
|
* @param foodIndex index jídla v jídelním lístku daného umístění, pokud existuje
|
||||||
* @param date datum, ke kterému se volba vztahuje
|
* @param date datum, ke kterému se volba vztahuje
|
||||||
* @returns
|
* @returns
|
||||||
*/
|
*/
|
||||||
export async function removeChoice(login: string, trusted: boolean, locationIndex: number, foodIndex: number, date?: Date) {
|
export async function removeChoice(login: string, trusted: boolean, locationKey: LocationKey, foodIndex: number, date?: Date) {
|
||||||
const selectedDay = formatDate(date ?? getToday());
|
const selectedDay = formatDate(date ?? getToday());
|
||||||
let data: DayData = await storage.getData(selectedDay);
|
let data: DayData = await storage.getData(selectedDay);
|
||||||
validateTrusted(data, login, trusted);
|
validateTrusted(data, login, trusted);
|
||||||
if (locationIndex in data.choices) {
|
if (locationKey in data.choices) {
|
||||||
if (login in data.choices[locationIndex]) {
|
if (data.choices[locationKey] && login in data.choices[locationKey]) {
|
||||||
const index = data.choices[locationIndex][login].options.indexOf(foodIndex);
|
const index = data.choices[locationKey][login].options.indexOf(foodIndex);
|
||||||
if (index > -1) {
|
if (index > -1) {
|
||||||
data.choices[locationIndex][login].options.splice(index, 1)
|
data.choices[locationKey][login].options.splice(index, 1)
|
||||||
await storage.setData(selectedDay, data);
|
await storage.setData(selectedDay, data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -247,10 +275,11 @@ export async function removeChoice(login: string, trusted: boolean, locationInde
|
|||||||
async function removeChoiceIfPresent(login: string, date: string) {
|
async function removeChoiceIfPresent(login: string, date: string) {
|
||||||
let data: DayData = await storage.getData(date);
|
let data: DayData = await storage.getData(date);
|
||||||
for (const key of Object.keys(data.choices)) {
|
for (const key of Object.keys(data.choices)) {
|
||||||
if (login in data.choices[key]) {
|
const locationKey = key as LocationKey;
|
||||||
delete data.choices[key][login];
|
if (data.choices[locationKey] && login in data.choices[locationKey]) {
|
||||||
if (Object.keys(data.choices[key]).length === 0) {
|
delete data.choices[locationKey][login];
|
||||||
delete data.choices[key];
|
if (Object.keys(data.choices[locationKey]).length === 0) {
|
||||||
|
delete data.choices[locationKey];
|
||||||
}
|
}
|
||||||
await storage.setData(date, data);
|
await storage.setData(date, data);
|
||||||
}
|
}
|
||||||
@@ -285,13 +314,13 @@ function validateTrusted(data: ClientData, login: string, trusted: boolean) {
|
|||||||
*
|
*
|
||||||
* @param login login uživatele
|
* @param login login uživatele
|
||||||
* @param trusted příznak, zda se jedná o ověřeného uživatele
|
* @param trusted příznak, zda se jedná o ověřeného uživatele
|
||||||
* @param locationIndex vybrané "umístění"
|
* @param locationKey vybrané "umístění"
|
||||||
* @param foodIndex volitelný index jídla v daném umístění
|
* @param foodIndex volitelný index jídla v daném umístění
|
||||||
* @param trusted příznak, zda se jedná o ověřeného uživatele
|
* @param trusted příznak, zda se jedná o ověřeného uživatele
|
||||||
* @param date datum, ke kterému se volba vztahuje
|
* @param date datum, ke kterému se volba vztahuje
|
||||||
* @returns aktuální data
|
* @returns aktuální data
|
||||||
*/
|
*/
|
||||||
export async function addChoice(login: string, trusted: boolean, locationIndex: number, foodIndex?: number, date?: Date) {
|
export async function addChoice(login: string, trusted: boolean, locationKey: LocationKey, foodIndex?: number, date?: Date) {
|
||||||
const usedDate = date ?? getToday();
|
const usedDate = date ?? getToday();
|
||||||
await initIfNeeded(usedDate);
|
await initIfNeeded(usedDate);
|
||||||
const selectedDate = formatDate(usedDate);
|
const selectedDate = formatDate(usedDate);
|
||||||
@@ -301,17 +330,21 @@ export async function addChoice(login: string, trusted: boolean, locationIndex:
|
|||||||
if (foodIndex == null) {
|
if (foodIndex == null) {
|
||||||
data = await removeChoiceIfPresent(login, selectedDate);
|
data = await removeChoiceIfPresent(login, selectedDate);
|
||||||
}
|
}
|
||||||
if (!(locationIndex in data.choices)) {
|
// TODO vytáhnout inicializaci "prázdné struktury" do vlastní funkce
|
||||||
data.choices[locationIndex] = {};
|
if (!(data.choices[locationKey])) {
|
||||||
|
data.choices[locationKey] = {}
|
||||||
}
|
}
|
||||||
if (!(login in data.choices[locationIndex])) {
|
if (!(login in data.choices[locationKey])) {
|
||||||
data.choices[locationIndex][login] = {
|
if (!data.choices[locationKey]) {
|
||||||
|
data.choices[locationKey] = {}
|
||||||
|
}
|
||||||
|
data.choices[locationKey][login] = {
|
||||||
trusted,
|
trusted,
|
||||||
options: []
|
options: []
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
if (foodIndex != null && !data.choices[locationIndex][login].options.includes(foodIndex)) {
|
if (foodIndex != null && !data.choices[locationKey][login].options.includes(foodIndex)) {
|
||||||
data.choices[locationIndex][login].options.push(foodIndex);
|
data.choices[locationKey][login].options.push(foodIndex);
|
||||||
}
|
}
|
||||||
await storage.setData(selectedDate, data);
|
await storage.setData(selectedDate, data);
|
||||||
return data;
|
return data;
|
||||||
|
|||||||
@@ -1,11 +1,13 @@
|
|||||||
import { Choices } from "../../types";
|
import { Choices, LocationKey } from "../../types";
|
||||||
|
|
||||||
/** Vrátí datum v ISO formátu. */
|
/** Vrátí datum v ISO formátu. */
|
||||||
export function formatDate(date: Date) {
|
export function formatDate(date: Date, format?: string) {
|
||||||
let currentDay = String(date.getDate()).padStart(2, '0');
|
let day = String(date.getDate()).padStart(2, '0');
|
||||||
let currentMonth = String(date.getMonth() + 1).padStart(2, "0");
|
let month = String(date.getMonth() + 1).padStart(2, "0");
|
||||||
let currentYear = date.getFullYear();
|
let year = String(date.getFullYear());
|
||||||
return `${currentYear}-${currentMonth}-${currentDay}`;
|
|
||||||
|
const f = (format === undefined) ? 'YYYY-MM-DD' : format;
|
||||||
|
return f.replace('DD', day).replace('MM', month).replace('YYYY', year);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Vrátí human-readable reprezentaci předaného data pro zobrazení. */
|
/** Vrátí human-readable reprezentaci předaného data pro zobrazení. */
|
||||||
@@ -110,21 +112,21 @@ export const checkBodyParams = (req: any, paramNames: string[]) => {
|
|||||||
// TODO umístit do samostatného souboru
|
// TODO umístit do samostatného souboru
|
||||||
export class InsufficientPermissions extends Error { }
|
export class InsufficientPermissions extends Error { }
|
||||||
|
|
||||||
export const getUsersByLocation = (data: Choices, login: string): string[] => {
|
export const getUsersByLocation = (choices: Choices, login: string): string[] => {
|
||||||
const result: string[] = [];
|
const result: string[] = [];
|
||||||
|
|
||||||
for (const location in data) {
|
for (const location of Object.entries(choices)) {
|
||||||
if (data.hasOwnProperty(location)) {
|
const locationKey = location[0] as LocationKey;
|
||||||
if (data[location][login]) {
|
const locationValue = location[1];
|
||||||
for (const username in data[location]) {
|
if (locationValue[login]) {
|
||||||
if (data[location].hasOwnProperty(username)) {
|
for (const username in choices[locationKey]) {
|
||||||
|
if (choices[locationKey].hasOwnProperty(username)) {
|
||||||
result.push(username);
|
result.push(username);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
@@ -1,20 +1,20 @@
|
|||||||
import { FeatureRequest, PizzaOrder } from "./Types";
|
import { FeatureRequest, LocationKey, PizzaOrder } from "./Types";
|
||||||
|
|
||||||
|
export type ILocationKey = {
|
||||||
|
locationKey: LocationKey,
|
||||||
|
}
|
||||||
|
|
||||||
export type IDayIndex = {
|
export type IDayIndex = {
|
||||||
dayIndex?: number,
|
dayIndex?: number,
|
||||||
}
|
}
|
||||||
|
|
||||||
export type AddChoiceRequest = IDayIndex & {
|
export type AddChoiceRequest = IDayIndex & ILocationKey & {
|
||||||
locationIndex: number,
|
|
||||||
foodIndex?: number,
|
foodIndex?: number,
|
||||||
}
|
}
|
||||||
|
|
||||||
export type RemoveChoicesRequest = IDayIndex & {
|
export type RemoveChoicesRequest = IDayIndex & ILocationKey;
|
||||||
locationIndex: number,
|
|
||||||
}
|
|
||||||
|
|
||||||
export type RemoveChoiceRequest = IDayIndex & {
|
export type RemoveChoiceRequest = IDayIndex & ILocationKey & {
|
||||||
locationIndex: number,
|
|
||||||
foodIndex: number,
|
foodIndex: number,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -3,6 +3,8 @@ export enum Restaurants {
|
|||||||
SLADOVNICKA = 'sladovnicka',
|
SLADOVNICKA = 'sladovnicka',
|
||||||
// UMOTLIKU = 'uMotliku',
|
// UMOTLIKU = 'uMotliku',
|
||||||
TECHTOWER = 'techTower',
|
TECHTOWER = 'techTower',
|
||||||
|
ZASTAVKAUMICHALA = 'zastavkaUmichala',
|
||||||
|
SENKSERIKOVA = 'senkSerikova',
|
||||||
}
|
}
|
||||||
|
|
||||||
export type FoodChoices = {
|
export type FoodChoices = {
|
||||||
@@ -12,10 +14,11 @@ export type FoodChoices = {
|
|||||||
note?: string,
|
note?: string,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO okomentovat / rozdělit
|
||||||
export type Choices = {
|
export type Choices = {
|
||||||
[location: string]: {
|
[location in LocationKey]?: {
|
||||||
[login: string]: FoodChoices
|
[login: string]: FoodChoices
|
||||||
},
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Velikost konkrétní pizzy */
|
/** Velikost konkrétní pizzy */
|
||||||
@@ -88,7 +91,7 @@ export type DayData = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** Veškerá data pro zobrazení na klientovi. */
|
/** Veškerá data pro zobrazení na klientovi. */
|
||||||
export type ClientData extends DayData = {
|
export type ClientData = DayData & {
|
||||||
todayWeekIndex?: number, // index dnešního dne v týdnu (0-6)
|
todayWeekIndex?: number, // index dnešního dne v týdnu (0-6)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -112,6 +115,8 @@ export enum Locations {
|
|||||||
SLADOVNICKA = 'Sladovnická',
|
SLADOVNICKA = 'Sladovnická',
|
||||||
// UMOTLIKU = 'U Motlíků',
|
// UMOTLIKU = 'U Motlíků',
|
||||||
TECHTOWER = 'TechTower',
|
TECHTOWER = 'TechTower',
|
||||||
|
ZASTAVKAUMICHALA = 'Zastávka u Michala',
|
||||||
|
SENKSERIKOVA = 'Pivovarský šenk Šeříková',
|
||||||
SPSE = 'SPŠE',
|
SPSE = 'SPŠE',
|
||||||
PIZZA = 'Pizza day',
|
PIZZA = 'Pizza day',
|
||||||
OBJEDNAVAM = 'Budu objednávat',
|
OBJEDNAVAM = 'Budu objednávat',
|
||||||
@@ -119,6 +124,9 @@ export enum Locations {
|
|||||||
ROZHODUJI = 'Rozhoduji se',
|
ROZHODUJI = 'Rozhoduji se',
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO totéž
|
||||||
|
export type LocationKey = keyof typeof Locations;
|
||||||
|
|
||||||
export enum UdalostEnum {
|
export enum UdalostEnum {
|
||||||
ZAHAJENA_PIZZA = "Zahájen pizza day",
|
ZAHAJENA_PIZZA = "Zahájen pizza day",
|
||||||
OBJEDNANA_PIZZA = "Objednána pizza",
|
OBJEDNANA_PIZZA = "Objednána pizza",
|
||||||
|
|||||||
Reference in New Issue
Block a user