Možnost výběru konkrétních jídel

This commit is contained in:
2023-07-25 23:53:05 +02:00
parent 24c301b141
commit bbf1cf1850
3 changed files with 138 additions and 68 deletions

View File

@@ -204,47 +204,52 @@ app.post("/api/finishDelivery", (req, res) => {
io.emit("message", data);
res.status(200).json({});
});
[
app.post("/api/addChoice", (req, res) => {
const login = getLogin(parseToken(req));
if (req.body.locationIndex > -1) {
const data = addChoice(login, 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) => {
const login = getLogin(parseToken(req));
const data = removeChoices(login, req.body.locationIndex);
io.emit("message", data);
res.status(200).json(data);
});
app.post("/api/removeChoices", (req, res) => {
const login = getLogin(parseToken(req));
console.log("Remove choices", req.body.location); // TODO smazat
const data = removeChoices(login, req.body.location);
io.emit("message", data);
res.status(200).json(data);
app.post("/api/removeChoice", (req, res) => {
const login = getLogin(parseToken(req));
const data = removeChoice(login, req.body.locationIndex, req.body.foodIndex);
io.emit("message", data);
res.status(200).json(data);
});
app.post("/api/updateNote", (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);
io.emit("message", data);
res.status(200).json(data);
});
io.on("connection", (socket) => {
console.log(`New client connected: ${socket.id}`);
socket.on("message", (message) => {
io.emit("message", message);
});
app.post("/api/removeChoice", (req, res) => {
const login = getLogin(parseToken(req));
console.log("Remove choice", req.body.location, req.body.foodIndex); // TODO smazat
const data = removeChoice(login, req.body.location, req.body.foodIndex);
io.emit("message", data);
res.status(200).json(data);
});
app.post("/api/updateNote", (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);
io.emit("message", data);
res.status(200).json(data);
});
io.on("connection", (socket) => {
console.log(`New client connected: ${socket.id}`);
socket.on("message", (message) => {
io.emit("message", message);
});
socket.on("disconnect", () => {
console.log(`Client disconnected: ${socket.id}`);
});
socket.on("disconnect", () => {
console.log(`Client disconnected: ${socket.id}`);
});
});
const PORT = process.env.PORT || 3001;
const HOST = process.env.HOST || '0.0.0.0';