Možnost hlasování o nových funkcích

This commit is contained in:
2023-09-27 18:35:18 +02:00
parent 401833f763
commit 8e285e9197
7 changed files with 177 additions and 11 deletions

View File

@@ -9,6 +9,7 @@ import path from 'path';
import { getQr } from "./qr";
import { generateToken, getLogin, getTrusted, verify } from "./auth";
import { InsufficientPermissions, getDayOfWeekIndex } from "./utils";
import { getUserVotes, updateFeatureVote } from "./voting";
const ENVIRONMENT = process.env.NODE_ENV || 'production';
dotenv.config({ path: path.resolve(__dirname, `./.env.${ENVIRONMENT}`) });
@@ -324,6 +325,24 @@ app.post("/api/updatePizzaFee", async (req, res, next) => {
} catch (e: any) { next(e) }
});
app.get("/api/getFeatureVotes", async (req, res) => {
const login = getLogin(parseToken(req));
const data = await getUserVotes(login);
res.status(200).json(data);
});
app.post("/api/updateFeatureVote", async (req, res, next) => {
const login = getLogin(parseToken(req));
if (req.body?.option == null || req.body?.active == null) {
res.status(400).json({ error: "Chybné parametry volání" });
}
try {
const data = await updateFeatureVote(login, req.body.option, req.body.active);
io.emit("message", data);
res.status(200).json(data);
} catch (e: any) { next(e) }
});
// Middleware pro zpracování chyb
app.use((err: any, req: any, res: any, next: any) => {
if (err instanceof InsufficientPermissions) {