Zavedení podpory pro Redis, agnostické úložiště dat
This commit is contained in:
@@ -105,8 +105,8 @@ app.use((req, res, next) => {
|
||||
});
|
||||
|
||||
/** Vrátí data pro aktuální den. */
|
||||
app.get("/api/data", (req, res) => {
|
||||
res.status(200).json(getData());
|
||||
app.get("/api/data", async (req, res) => {
|
||||
res.status(200).json(await getData());
|
||||
});
|
||||
|
||||
/** Vrátí obědové menu pro dostupné podniky. */
|
||||
@@ -122,29 +122,28 @@ app.get("/api/food", async (req, res) => {
|
||||
});
|
||||
|
||||
/** Vrátí seznam dostupných pizz. */
|
||||
app.get("/api/pizza", (req, res) => {
|
||||
fetchPizzy().then(pizzaList => {
|
||||
// console.log("Výsledek", pizzaList);
|
||||
res.status(200).json(pizzaList);
|
||||
});
|
||||
app.get("/api/pizza", async (req, res) => {
|
||||
const pizzaList = await fetchPizzy();
|
||||
// console.log("Výsledek", pizzaList);
|
||||
res.status(200).json(pizzaList);
|
||||
});
|
||||
|
||||
/** Založí pizza day pro aktuální den, za předpokladu že dosud neexistuje. */
|
||||
app.post("/api/createPizzaDay", (req, res) => {
|
||||
app.post("/api/createPizzaDay", async (req, res) => {
|
||||
const login = getLogin(parseToken(req));
|
||||
const data = createPizzaDay(login);
|
||||
const data = await createPizzaDay(login);
|
||||
res.status(200).json(data);
|
||||
io.emit("message", data);
|
||||
});
|
||||
|
||||
/** Smaže pizza day pro aktuální den, za předpokladu že existuje. */
|
||||
app.post("/api/deletePizzaDay", (req, res) => {
|
||||
app.post("/api/deletePizzaDay", async (req, res) => {
|
||||
const login = getLogin(parseToken(req));
|
||||
const data = deletePizzaDay(login);
|
||||
const data = await deletePizzaDay(login);
|
||||
io.emit("message", data);
|
||||
});
|
||||
|
||||
app.post("/api/addPizza", (req, res) => {
|
||||
app.post("/api/addPizza", async (req, res) => {
|
||||
const login = getLogin(parseToken(req));
|
||||
if (isNaN(req.body?.pizzaIndex)) {
|
||||
throw Error("Nebyl předán index pizzy");
|
||||
@@ -154,88 +153,87 @@ app.post("/api/addPizza", (req, res) => {
|
||||
throw Error("Nebyl předán index velikosti pizzy");
|
||||
}
|
||||
const pizzaSizeIndex = req.body.pizzaSizeIndex;
|
||||
fetchPizzy().then(pizzy => {
|
||||
if (!pizzy[pizzaIndex]) {
|
||||
throw Error("Neplatný index pizzy: " + pizzaIndex);
|
||||
}
|
||||
if (!pizzy[pizzaIndex].sizes[pizzaSizeIndex]) {
|
||||
throw Error("Neplatný index velikosti pizzy: " + pizzaSizeIndex);
|
||||
}
|
||||
const data = addPizzaOrder(login, pizzy[pizzaIndex], pizzy[pizzaIndex].sizes[pizzaSizeIndex]);
|
||||
io.emit("message", data);
|
||||
res.status(200).json({});
|
||||
})
|
||||
const pizzy = await fetchPizzy();
|
||||
if (!pizzy[pizzaIndex]) {
|
||||
throw Error("Neplatný index pizzy: " + pizzaIndex);
|
||||
}
|
||||
if (!pizzy[pizzaIndex].sizes[pizzaSizeIndex]) {
|
||||
throw Error("Neplatný index velikosti pizzy: " + pizzaSizeIndex);
|
||||
}
|
||||
const data = await addPizzaOrder(login, pizzy[pizzaIndex], pizzy[pizzaIndex].sizes[pizzaSizeIndex]);
|
||||
io.emit("message", data);
|
||||
res.status(200).json({});
|
||||
});
|
||||
|
||||
app.post("/api/removePizza", (req, res) => {
|
||||
app.post("/api/removePizza", async (req, res) => {
|
||||
const login = getLogin(parseToken(req));
|
||||
if (!req.body?.pizzaOrder) {
|
||||
throw Error("Nebyla předána objednávka");
|
||||
}
|
||||
const data = removePizzaOrder(login, req.body?.pizzaOrder);
|
||||
const data = await removePizzaOrder(login, req.body?.pizzaOrder);
|
||||
io.emit("message", data);
|
||||
res.status(200).json({});
|
||||
});
|
||||
|
||||
app.post("/api/lockPizzaDay", (req, res) => {
|
||||
app.post("/api/lockPizzaDay", async (req, res) => {
|
||||
const login = getLogin(parseToken(req));
|
||||
const data = lockPizzaDay(login);
|
||||
const data = await lockPizzaDay(login);
|
||||
io.emit("message", data);
|
||||
res.status(200).json({});
|
||||
});
|
||||
|
||||
app.post("/api/unlockPizzaDay", (req, res) => {
|
||||
app.post("/api/unlockPizzaDay", async (req, res) => {
|
||||
const login = getLogin(parseToken(req));
|
||||
const data = unlockPizzaDay(login);
|
||||
const data = await unlockPizzaDay(login);
|
||||
io.emit("message", data);
|
||||
res.status(200).json({});
|
||||
});
|
||||
|
||||
app.post("/api/finishOrder", (req, res) => {
|
||||
app.post("/api/finishOrder", async (req, res) => {
|
||||
const login = getLogin(parseToken(req));
|
||||
const data = finishPizzaOrder(login);
|
||||
const data = await finishPizzaOrder(login);
|
||||
io.emit("message", data);
|
||||
res.status(200).json({});
|
||||
});
|
||||
|
||||
app.post("/api/finishDelivery", (req, res) => {
|
||||
app.post("/api/finishDelivery", async (req, res) => {
|
||||
const login = getLogin(parseToken(req));
|
||||
const data = finishPizzaDelivery(login, req.body.bankAccount, req.body.bankAccountHolder);
|
||||
const data = await finishPizzaDelivery(login, req.body.bankAccount, req.body.bankAccountHolder);
|
||||
io.emit("message", data);
|
||||
res.status(200).json({});
|
||||
});
|
||||
|
||||
app.post("/api/addChoice", (req, res) => {
|
||||
app.post("/api/addChoice", async (req, res) => {
|
||||
const login = getLogin(parseToken(req));
|
||||
const trusted = getTrusted(parseToken(req));
|
||||
if (req.body.locationIndex > -1) {
|
||||
const data = addChoice(login, trusted, req.body.locationIndex, req.body.foodIndex);
|
||||
const data = await addChoice(login, trusted, req.body.locationIndex, req.body.foodIndex);
|
||||
io.emit("message", data);
|
||||
res.status(200).json(data);
|
||||
}
|
||||
res.status(400); // TODO přidat popis chyby
|
||||
});
|
||||
|
||||
app.post("/api/removeChoices", (req, res) => {
|
||||
app.post("/api/removeChoices", async (req, res) => {
|
||||
const login = getLogin(parseToken(req));
|
||||
const data = removeChoices(login, req.body.locationIndex);
|
||||
const data = await removeChoices(login, req.body.locationIndex);
|
||||
io.emit("message", data);
|
||||
res.status(200).json(data);
|
||||
});
|
||||
|
||||
app.post("/api/removeChoice", (req, res) => {
|
||||
app.post("/api/removeChoice", async (req, res) => {
|
||||
const login = getLogin(parseToken(req));
|
||||
const data = removeChoice(login, req.body.locationIndex, req.body.foodIndex);
|
||||
const data = await removeChoice(login, req.body.locationIndex, req.body.foodIndex);
|
||||
io.emit("message", data);
|
||||
res.status(200).json(data);
|
||||
});
|
||||
|
||||
app.post("/api/updateNote", (req, res) => {
|
||||
app.post("/api/updateNote", async (req, res) => {
|
||||
const login = getLogin(parseToken(req));
|
||||
if (req.body.note && req.body.note.length > 100) {
|
||||
throw Error("Poznámka může mít maximálně 100 znaků");
|
||||
}
|
||||
const data = updateNote(login, req.body.note);
|
||||
const data = await updateNote(login, req.body.note);
|
||||
io.emit("message", data);
|
||||
res.status(200).json(data);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user