NOMERGE: Přenos změn
This commit is contained in:
@@ -3,13 +3,13 @@ import { Server } from "socket.io";
|
||||
import bodyParser from "body-parser";
|
||||
import { fetchPizzy } from "./chefie";
|
||||
import cors from 'cors';
|
||||
import { addPizzaOrder, createPizzaDay, deletePizzaDay, finishPizzaDelivery, finishPizzaOrder, getData, lockPizzaDay, removePizzaOrder, unlockPizzaDay, updateChoice, updateNote } from "./service";
|
||||
import { addChoice, addPizzaOrder, createPizzaDay, deletePizzaDay, finishPizzaDelivery, finishPizzaOrder, getData, lockPizzaDay, removeChoice, removeChoices, removePizzaOrder, unlockPizzaDay, updateNote } from "./service";
|
||||
import dotenv from 'dotenv';
|
||||
import path from 'path';
|
||||
import { getMenuSladovnicka, getMenuTechTower, getMenuUMotliku } from "./restaurants";
|
||||
import { getQr } from "./qr";
|
||||
import { generateToken, getLogin, verify } from "./auth";
|
||||
import { Restaurants } from "../../types";
|
||||
import { Locations, Restaurants } from "../../types";
|
||||
|
||||
const ENVIRONMENT = process.env.NODE_ENV || 'production';
|
||||
dotenv.config({ path: path.resolve(__dirname, `./.env.${ENVIRONMENT}`) });
|
||||
@@ -35,6 +35,15 @@ app.use(cors({
|
||||
origin: '*'
|
||||
}));
|
||||
|
||||
// app.use((req, res, next) => {
|
||||
// console.log("--- Request ---")
|
||||
// console.log(req.url);
|
||||
// console.log(req.baseUrl);
|
||||
// console.log(req.originalUrl);
|
||||
// console.log(req.path);
|
||||
// next();
|
||||
// });
|
||||
|
||||
app.use(express.static('public'))
|
||||
|
||||
const parseToken = (req: any) => {
|
||||
@@ -195,35 +204,47 @@ app.post("/api/finishDelivery", (req, res) => {
|
||||
io.emit("message", data);
|
||||
res.status(200).json({});
|
||||
});
|
||||
|
||||
app.post("/api/updateChoice", (req, res) => {
|
||||
const login = getLogin(parseToken(req));
|
||||
const data = updateChoice(login, req.body.choice);
|
||||
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/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);
|
||||
});
|
||||
|
||||
socket.on("disconnect", () => {
|
||||
console.log(`Client disconnected: ${socket.id}`);
|
||||
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}`);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
const PORT = process.env.PORT || 3001;
|
||||
const HOST = process.env.HOST || '0.0.0.0';
|
||||
|
||||
Reference in New Issue
Block a user