Oprava mizejícího Pizza day
This commit is contained in:
parent
74c8ab9e39
commit
3460d69899
@ -353,6 +353,7 @@ function App() {
|
|||||||
Poslední změny:
|
Poslední změny:
|
||||||
<ul>
|
<ul>
|
||||||
<li>Parsování jídelních lístků na celý týden</li>
|
<li>Parsování jídelních lístků na celý týden</li>
|
||||||
|
<li>Oprava mizejícího Pizza day</li>
|
||||||
</ul>
|
</ul>
|
||||||
</Alert>
|
</Alert>
|
||||||
{dayIndex != null &&
|
{dayIndex != null &&
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import express from "express";
|
import express from "express";
|
||||||
import { getLogin, getTrusted } from "../auth";
|
import { getLogin, getTrusted } from "../auth";
|
||||||
import { getDateForWeekIndex, addChoice, removeChoices, removeChoice, updateDepartureTime, getToday } from "../service";
|
import { getDateForWeekIndex, addChoice, removeChoices, removeChoice, updateDepartureTime, getToday, addVolatileData } from "../service";
|
||||||
import { getDayOfWeekIndex, parseToken } from "../utils";
|
import { getDayOfWeekIndex, parseToken } from "../utils";
|
||||||
import { getWebsocket } from "../websocket";
|
import { getWebsocket } from "../websocket";
|
||||||
|
|
||||||
@ -44,7 +44,7 @@ router.post("/addChoice", async (req, res, next) => {
|
|||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
const data = await addChoice(login, trusted, req.body.locationIndex, req.body.foodIndex, date);
|
const data = await addChoice(login, trusted, req.body.locationIndex, req.body.foodIndex, date);
|
||||||
getWebsocket().emit("message", 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) }
|
||||||
}
|
}
|
||||||
@ -66,7 +66,7 @@ router.post("/removeChoices", async (req, res, next) => {
|
|||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
const data = await removeChoices(login, trusted, req.body.locationIndex, date);
|
const data = await removeChoices(login, trusted, req.body.locationIndex, date);
|
||||||
getWebsocket().emit("message", 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) }
|
||||||
});
|
});
|
||||||
@ -86,7 +86,7 @@ router.post("/removeChoice", async (req, res, next) => {
|
|||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
const data = await removeChoice(login, trusted, req.body.locationIndex, req.body.foodIndex, date);
|
const data = await removeChoice(login, trusted, req.body.locationIndex, req.body.foodIndex, date);
|
||||||
getWebsocket().emit("message", 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) }
|
||||||
});
|
});
|
||||||
@ -105,7 +105,7 @@ router.post("/changeDepartureTime", async (req, res, next) => {
|
|||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
const data = await updateDepartureTime(login, req.body?.time, date);
|
const data = await updateDepartureTime(login, req.body?.time, date);
|
||||||
getWebsocket().emit("message", 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) }
|
||||||
});
|
});
|
||||||
|
@ -3,6 +3,7 @@ import { getLogin } from "../auth";
|
|||||||
import { createPizzaDay, deletePizzaDay, getPizzaList, addPizzaOrder, removePizzaOrder, lockPizzaDay, unlockPizzaDay, finishPizzaOrder, finishPizzaDelivery, updatePizzaDayNote, updatePizzaFee } from "../pizza";
|
import { createPizzaDay, deletePizzaDay, getPizzaList, addPizzaOrder, removePizzaOrder, lockPizzaDay, unlockPizzaDay, finishPizzaOrder, finishPizzaDelivery, updatePizzaDayNote, updatePizzaFee } from "../pizza";
|
||||||
import { parseToken } from "../utils";
|
import { parseToken } from "../utils";
|
||||||
import { getWebsocket } from "../websocket";
|
import { getWebsocket } from "../websocket";
|
||||||
|
import { addVolatileData } from "../service";
|
||||||
|
|
||||||
const router = express.Router();
|
const router = express.Router();
|
||||||
|
|
||||||
@ -11,14 +12,14 @@ router.post("/create", async (req, res) => {
|
|||||||
const login = getLogin(parseToken(req));
|
const login = getLogin(parseToken(req));
|
||||||
const data = await createPizzaDay(login);
|
const data = await createPizzaDay(login);
|
||||||
res.status(200).json(data);
|
res.status(200).json(data);
|
||||||
getWebsocket().emit("message", data);
|
getWebsocket().emit("message", await addVolatileData(data));
|
||||||
});
|
});
|
||||||
|
|
||||||
/** Smaže pizza day pro aktuální den, za předpokladu že existuje. */
|
/** Smaže pizza day pro aktuální den, za předpokladu že existuje. */
|
||||||
router.post("/delete", async (req, res) => {
|
router.post("/delete", async (req, res) => {
|
||||||
const login = getLogin(parseToken(req));
|
const login = getLogin(parseToken(req));
|
||||||
const data = await deletePizzaDay(login);
|
const data = await deletePizzaDay(login);
|
||||||
getWebsocket().emit("message", data);
|
getWebsocket().emit("message", await addVolatileData(data));
|
||||||
});
|
});
|
||||||
|
|
||||||
router.post("/add", async (req, res) => {
|
router.post("/add", async (req, res) => {
|
||||||
@ -42,7 +43,7 @@ router.post("/add", async (req, res) => {
|
|||||||
throw Error("Neplatný index velikosti pizzy: " + pizzaSizeIndex);
|
throw Error("Neplatný index velikosti pizzy: " + pizzaSizeIndex);
|
||||||
}
|
}
|
||||||
const data = await addPizzaOrder(login, pizzy[pizzaIndex], pizzy[pizzaIndex].sizes[pizzaSizeIndex]);
|
const data = await addPizzaOrder(login, pizzy[pizzaIndex], pizzy[pizzaIndex].sizes[pizzaSizeIndex]);
|
||||||
getWebsocket().emit("message", data);
|
getWebsocket().emit("message", await addVolatileData(data));
|
||||||
res.status(200).json({});
|
res.status(200).json({});
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -52,35 +53,35 @@ router.post("/remove", async (req, res) => {
|
|||||||
throw Error("Nebyla předána objednávka");
|
throw Error("Nebyla předána objednávka");
|
||||||
}
|
}
|
||||||
const data = await removePizzaOrder(login, req.body?.pizzaOrder);
|
const data = await removePizzaOrder(login, req.body?.pizzaOrder);
|
||||||
getWebsocket().emit("message", data);
|
getWebsocket().emit("message", await addVolatileData(data));
|
||||||
res.status(200).json({});
|
res.status(200).json({});
|
||||||
});
|
});
|
||||||
|
|
||||||
router.post("/lock", async (req, res) => {
|
router.post("/lock", async (req, res) => {
|
||||||
const login = getLogin(parseToken(req));
|
const login = getLogin(parseToken(req));
|
||||||
const data = await lockPizzaDay(login);
|
const data = await lockPizzaDay(login);
|
||||||
getWebsocket().emit("message", data);
|
getWebsocket().emit("message", await addVolatileData(data));
|
||||||
res.status(200).json({});
|
res.status(200).json({});
|
||||||
});
|
});
|
||||||
|
|
||||||
router.post("/unlock", async (req, res) => {
|
router.post("/unlock", async (req, res) => {
|
||||||
const login = getLogin(parseToken(req));
|
const login = getLogin(parseToken(req));
|
||||||
const data = await unlockPizzaDay(login);
|
const data = await unlockPizzaDay(login);
|
||||||
getWebsocket().emit("message", data);
|
getWebsocket().emit("message", await addVolatileData(data));
|
||||||
res.status(200).json({});
|
res.status(200).json({});
|
||||||
});
|
});
|
||||||
|
|
||||||
router.post("/finishOrder", async (req, res) => {
|
router.post("/finishOrder", async (req, res) => {
|
||||||
const login = getLogin(parseToken(req));
|
const login = getLogin(parseToken(req));
|
||||||
const data = await finishPizzaOrder(login);
|
const data = await finishPizzaOrder(login);
|
||||||
getWebsocket().emit("message", data);
|
getWebsocket().emit("message", await addVolatileData(data));
|
||||||
res.status(200).json({});
|
res.status(200).json({});
|
||||||
});
|
});
|
||||||
|
|
||||||
router.post("/finishDelivery", async (req, res) => {
|
router.post("/finishDelivery", async (req, res) => {
|
||||||
const login = getLogin(parseToken(req));
|
const login = getLogin(parseToken(req));
|
||||||
const data = await finishPizzaDelivery(login, req.body.bankAccount, req.body.bankAccountHolder);
|
const data = await finishPizzaDelivery(login, req.body.bankAccount, req.body.bankAccountHolder);
|
||||||
getWebsocket().emit("message", data);
|
getWebsocket().emit("message", await addVolatileData(data));
|
||||||
res.status(200).json({});
|
res.status(200).json({});
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -90,7 +91,7 @@ router.post("/updatePizzaDayNote", async (req, res) => {
|
|||||||
throw Error("Poznámka může mít maximálně 100 znaků");
|
throw Error("Poznámka může mít maximálně 100 znaků");
|
||||||
}
|
}
|
||||||
const data = await updatePizzaDayNote(login, req.body.note);
|
const data = await updatePizzaDayNote(login, req.body.note);
|
||||||
getWebsocket().emit("message", data);
|
getWebsocket().emit("message", await addVolatileData(data));
|
||||||
res.status(200).json(data);
|
res.status(200).json(data);
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -101,7 +102,7 @@ router.post("/updatePizzaFee", async (req, res, next) => {
|
|||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
const data = await updatePizzaFee(login, req.body.login, req.body.text, req.body.price);
|
const data = await updatePizzaFee(login, req.body.login, req.body.text, req.body.price);
|
||||||
getWebsocket().emit("message", 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) }
|
||||||
});
|
});
|
||||||
|
@ -2,7 +2,6 @@ import express from "express";
|
|||||||
import { getLogin } from "../auth";
|
import { getLogin } from "../auth";
|
||||||
import { parseToken } from "../utils";
|
import { parseToken } from "../utils";
|
||||||
import { getUserVotes, updateFeatureVote } from "../voting";
|
import { getUserVotes, updateFeatureVote } from "../voting";
|
||||||
import { getWebsocket } from "../websocket";
|
|
||||||
|
|
||||||
const router = express.Router();
|
const router = express.Router();
|
||||||
|
|
||||||
@ -19,7 +18,6 @@ router.post("/updateVote", async (req, res, next) => {
|
|||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
const data = await updateFeatureVote(login, req.body.option, req.body.active);
|
const data = await updateFeatureVote(login, req.body.option, req.body.active);
|
||||||
getWebsocket().emit("message", data);
|
|
||||||
res.status(200).json(data);
|
res.status(200).json(data);
|
||||||
} catch (e: any) { next(e) }
|
} catch (e: any) { next(e) }
|
||||||
});
|
});
|
||||||
|
@ -39,6 +39,17 @@ function getEmptyData(date?: Date): ClientData {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Přidá k datům "dopočítaná" data, která nejsou přímo uložena v databázi.
|
||||||
|
*
|
||||||
|
* @param data data z databáze
|
||||||
|
* @returns obohacená data
|
||||||
|
*/
|
||||||
|
export async function addVolatileData(data: ClientData): Promise<ClientData> {
|
||||||
|
data.todayWeekIndex = getDayOfWeekIndex(getToday());
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Vrátí veškerá klientská data pro předaný den, nebo aktuální den, pokud není předán.
|
* Vrátí veškerá klientská data pro předaný den, nebo aktuální den, pokud není předán.
|
||||||
*/
|
*/
|
||||||
@ -46,13 +57,13 @@ export async function getData(date?: Date): Promise<ClientData> {
|
|||||||
const targetDate = date ?? getToday();
|
const targetDate = date ?? getToday();
|
||||||
const dateString = formatDate(targetDate);
|
const dateString = formatDate(targetDate);
|
||||||
const data: DayData = await storage.getData(dateString) || getEmptyData(date);
|
const data: DayData = await storage.getData(dateString) || getEmptyData(date);
|
||||||
const clientData: ClientData = { ...data };
|
let clientData: ClientData = { ...data };
|
||||||
clientData.todayWeekIndex = getDayOfWeekIndex(getToday());
|
|
||||||
clientData.menus = {
|
clientData.menus = {
|
||||||
[Restaurants.SLADOVNICKA]: await getRestaurantMenu(Restaurants.SLADOVNICKA, targetDate),
|
[Restaurants.SLADOVNICKA]: await getRestaurantMenu(Restaurants.SLADOVNICKA, date),
|
||||||
[Restaurants.UMOTLIKU]: await getRestaurantMenu(Restaurants.UMOTLIKU, targetDate),
|
[Restaurants.UMOTLIKU]: await getRestaurantMenu(Restaurants.UMOTLIKU, date),
|
||||||
[Restaurants.TECHTOWER]: await getRestaurantMenu(Restaurants.TECHTOWER, targetDate),
|
[Restaurants.TECHTOWER]: await getRestaurantMenu(Restaurants.TECHTOWER, date),
|
||||||
}
|
}
|
||||||
|
clientData = await addVolatileData(clientData);
|
||||||
return clientData;
|
return clientData;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user