This commit is contained in:
parent
0d90453c38
commit
52769fc981
@ -18,8 +18,6 @@ import Loader from './components/Loader';
|
||||
import { getHumanDateTime, isInTheFuture } from './Utils';
|
||||
import NoteModal from './components/modals/NoteModal';
|
||||
import { useEasterEgg } from './context/eggs';
|
||||
import { Link } from 'react-router';
|
||||
import { STATS_URL } from './AppRoutes';
|
||||
import { ClientData, Food, PizzaOrder, DepartureTime, PizzaDayState, Restaurant, RestaurantDayMenu, RestaurantDayMenuMap, LunchChoice, UserLunchChoice, PizzaVariant, getData, getEasterEggImage, addPizza, removePizza, updatePizzaDayNote, createPizzaDay, deletePizzaDay, lockPizzaDay, unlockPizzaDay, finishOrder, finishDelivery, addChoice, jdemeObed, removeChoices, removeChoice, updateNote, changeDepartureTime } from '../../types';
|
||||
import { getLunchChoiceName } from './enums';
|
||||
|
||||
|
@ -37,9 +37,7 @@ export default function PizzaCalculatorModal({ isOpen, onClose }: Readonly<Props
|
||||
// 1. pizza
|
||||
if (diameter1Ref.current?.value) {
|
||||
const diameter1 = parseInt(diameter1Ref.current?.value);
|
||||
if (!r.pizza1) {
|
||||
r.pizza1 = {};
|
||||
}
|
||||
r.pizza1 ??= {};
|
||||
if (diameter1 && diameter1 > 0) {
|
||||
r.pizza1.diameter = diameter1;
|
||||
r.pizza1.area = Math.PI * Math.pow(diameter1 / 2, 2);
|
||||
@ -59,9 +57,7 @@ export default function PizzaCalculatorModal({ isOpen, onClose }: Readonly<Props
|
||||
// 2. pizza
|
||||
if (diameter2Ref.current?.value) {
|
||||
const diameter2 = parseInt(diameter2Ref.current?.value);
|
||||
if (!r.pizza2) {
|
||||
r.pizza2 = {};
|
||||
}
|
||||
r.pizza2 ??= {};
|
||||
if (diameter2 && diameter2 > 0) {
|
||||
r.pizza2.diameter = diameter2;
|
||||
r.pizza2.area = Math.PI * Math.pow(diameter2 / 2, 2);
|
||||
|
@ -8,49 +8,6 @@ import { NotifikaceData, NotifikaceInput } from '../../types';
|
||||
const ENVIRONMENT = process.env.NODE_ENV ?? 'production';
|
||||
dotenv.config({ path: path.resolve(__dirname, `../.env.${ENVIRONMENT}`) });
|
||||
|
||||
// const gotifyDataRaw = process.env.GOTIFY_SERVERS_AND_KEYS || "{}";
|
||||
// const gotifyData: GotifyServer[] = JSON.parse(gotifyDataRaw);
|
||||
// export const gotifyCall = async (data: NotififaceInput, gotifyServers?: GotifyServer[]): Promise<any[]> => {
|
||||
// if (!Array.isArray(gotifyServers)) {
|
||||
// return []
|
||||
// }
|
||||
// const urls = gotifyServers.flatMap(gotifyServer =>
|
||||
// gotifyServer.api_keys.map(apiKey => `${gotifyServer.server}/message?token=${apiKey}`));
|
||||
//
|
||||
// const dataPayload = {
|
||||
// title: "Luncher",
|
||||
// message: `${data.udalost} - spustil:${data.user}`,
|
||||
// priority: 7,
|
||||
// };
|
||||
//
|
||||
// const headers = { "Content-Type": "application/json" };
|
||||
//
|
||||
// const promises = urls.map(url =>
|
||||
// axios.post(url, dataPayload, { headers }).then(response => {
|
||||
// response.data = {
|
||||
// success: true,
|
||||
// message: "Notifikace doručena",
|
||||
// };
|
||||
// return response;
|
||||
// }).catch(error => {
|
||||
// if (axios.isAxiosError(error)) {
|
||||
// const axiosError = error as AxiosError;
|
||||
// if (axiosError.response) {
|
||||
// axiosError.response.data = {
|
||||
// success: false,
|
||||
// message: "fail",
|
||||
// };
|
||||
// console.log(error)
|
||||
// return axiosError.response;
|
||||
// }
|
||||
// }
|
||||
// // Handle unknown error without a response
|
||||
// console.log(error, "unknown error");
|
||||
// })
|
||||
// );
|
||||
// return promises;
|
||||
// };
|
||||
|
||||
export const ntfyCall = async (data: NotifikaceInput) => {
|
||||
const url = process.env.NTFY_HOST
|
||||
const username = process.env.NTFY_USERNAME;
|
||||
|
@ -96,9 +96,7 @@ export async function addPizzaOrder(login: string, pizza: Pizza, size: PizzaSize
|
||||
totalPrice: 0,
|
||||
hasQr: false,
|
||||
}
|
||||
if (!clientData.pizzaDay.orders) {
|
||||
clientData.pizzaDay.orders = [];
|
||||
}
|
||||
clientData.pizzaDay.orders ??= [];
|
||||
clientData.pizzaDay.orders.push(order);
|
||||
}
|
||||
const pizzaOrder: PizzaVariant = {
|
||||
@ -107,9 +105,7 @@ export async function addPizzaOrder(login: string, pizza: Pizza, size: PizzaSize
|
||||
size: size.size,
|
||||
price: size.price,
|
||||
}
|
||||
if (!order.pizzaList) {
|
||||
order.pizzaList = [];
|
||||
}
|
||||
order.pizzaList ??= [];
|
||||
order.pizzaList.push(pizzaOrder);
|
||||
order.totalPrice += pizzaOrder.price;
|
||||
await storage.setData(today, clientData);
|
||||
|
@ -300,9 +300,7 @@ export const getMenuTechTower = async (firstDayOfWeek: Date, mock: boolean = fal
|
||||
price = `${split.slice(1)[0]}\xA0Kč`
|
||||
name = split[0].replace('•', '');
|
||||
}
|
||||
if (result[currentDayIndex] == null) {
|
||||
result[currentDayIndex] = [];
|
||||
}
|
||||
result[currentDayIndex] ??= [];
|
||||
result[currentDayIndex].push({
|
||||
amount: '-',
|
||||
name,
|
||||
|
@ -1,6 +1,6 @@
|
||||
import express, { Request, Response } from "express";
|
||||
import { getLogin, getTrusted } from "../auth";
|
||||
import { addChoice, getDateForWeekIndex, getToday, removeChoice, removeChoices, updateDepartureTime, updateNote, getRestaurantMenu, fetchRestaurantWeekMenuData, saveRestaurantWeekMenu } from "../service";
|
||||
import { addChoice, getDateForWeekIndex, getToday, removeChoice, removeChoices, updateDepartureTime, updateNote, fetchRestaurantWeekMenuData, saveRestaurantWeekMenu } from "../service";
|
||||
import { getDayOfWeekIndex, parseToken, getFirstWorkDayOfWeek } from "../utils";
|
||||
import { getWebsocket } from "../websocket";
|
||||
import { callNotifikace } from "../notifikace";
|
||||
|
@ -381,9 +381,7 @@ export async function addChoice(login: string, trusted: boolean, locationKey: Lu
|
||||
removeChoiceIfPresent(login, usedDate, locationKey);
|
||||
}
|
||||
// TODO vytáhnout inicializaci "prázdné struktury" do vlastní funkce
|
||||
if (!(data.choices[locationKey])) {
|
||||
data.choices[locationKey] = {}
|
||||
}
|
||||
data.choices[locationKey] ??= {};
|
||||
if (!(login in data.choices[locationKey])) {
|
||||
if (!data.choices[locationKey]) {
|
||||
data.choices[locationKey] = {}
|
||||
|
@ -5,6 +5,12 @@
|
||||
* Postupem času lze předělat pro efektivnější využití Redis.
|
||||
*/
|
||||
export interface StorageInterface {
|
||||
|
||||
/**
|
||||
* Inicializuje úložiště, pokud je potřeba (např. připojení k databázi).
|
||||
*/
|
||||
initialize?(): Promise<void>;
|
||||
|
||||
/**
|
||||
* Vrátí příznak, zda existují data pro předaný klíč.
|
||||
* @param key klíč, pro který zjišťujeme data (typicky datum)
|
||||
|
@ -19,6 +19,13 @@ if (!process.env.STORAGE || process.env.STORAGE?.toLowerCase() === JSON_KEY) {
|
||||
throw Error("Nepodporovaná hodnota proměnné STORAGE: " + process.env.STORAGE + ", podporované jsou 'json' nebo 'redis'");
|
||||
}
|
||||
|
||||
(async () => {
|
||||
if (storage.initialize) {
|
||||
await storage.initialize();
|
||||
}
|
||||
})();
|
||||
|
||||
|
||||
export default function getStorage(): StorageInterface {
|
||||
return storage;
|
||||
}
|
||||
|
@ -11,6 +11,9 @@ export default class RedisStorage implements StorageInterface {
|
||||
const HOST = process.env.REDIS_HOST ?? 'localhost';
|
||||
const PORT = process.env.REDIS_PORT ?? 6379;
|
||||
client = createClient({ url: `redis://${HOST}:${PORT}` });
|
||||
}
|
||||
|
||||
async initialize() {
|
||||
client.connect();
|
||||
}
|
||||
|
||||
|
@ -29,9 +29,7 @@ export async function getUserVotes(login: string) {
|
||||
*/
|
||||
export async function updateFeatureVote(login: string, option: FeatureRequest, active: boolean): Promise<VotingData> {
|
||||
let data = await storage.getData<VotingData>(STORAGE_KEY);
|
||||
if (data == null) {
|
||||
data = {};
|
||||
}
|
||||
data ??= {};
|
||||
if (!(login in data)) {
|
||||
data[login] = [];
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user