spiele speichern

This commit is contained in:
klaas 2024-05-23 19:58:22 +00:00
parent 3826d61a92
commit 0aef28be60
2 changed files with 34 additions and 16 deletions

26
app.js
View File

@ -9,7 +9,7 @@ const moment=require('moment')
require('dotenv').config(); require('dotenv').config();
const app = express(); const app = express();
const port = 2000; const port = 2001;
// Middleware // Middleware
app.use(express.static(path.join(__dirname, 'public'))); app.use(express.static(path.join(__dirname, 'public')));
@ -19,7 +19,7 @@ app.use(express.urlencoded({ extended: false }));
// Session-Konfiguration // Session-Konfiguration
app.use(session({ app.use(session({
secret: 'your_secret_key', secret: process.env.SESSIONSECRET,
resave: false, resave: false,
saveUninitialized: false, saveUninitialized: false,
cookie: { maxAge: 1800000 } cookie: { maxAge: 1800000 }
@ -42,12 +42,12 @@ const requireAdmin = (req, res, next) => {
// Email-Konfiguration // Email-Konfiguration
const transporter = nodemailer.createTransport({ const transporter = nodemailer.createTransport({
host: "mail.boergmann.it", host: process.env.MAILHOST,
port: 465, port: 465,
secure: true, secure: true,
auth: { auth: {
user: 'klaas@boergmann.it', user: process.env.MAILUSER,
pass: 'XDsEXTdAUVkH5=V' pass: process.env.MAILPASS
} }
}); });
@ -356,6 +356,22 @@ app.post('/profile', requireAuth, async (req, res) => {
} }
}); });
app.post('/update-training', async (req, res) => {
const { trainingId, type, spielId } = req.body;
try {
if (type === 'spiel') {
await pool.query('UPDATE trainings SET spiel = $1 WHERE id = $2', [spielId, trainingId]);
} else if (type === 'aufwaermen') {
await pool.query('UPDATE trainings SET aufwaermen = $1 WHERE id = $2', [spielId, trainingId]);
}
res.redirect('/');
} catch (err) {
console.error(err);
res.send("Error " + err);
}
});
app.post('/update-leader', async (req, res) => { app.post('/update-leader', async (req, res) => {
const { trainingId, type, leaderId } = req.body; const { trainingId, type, leaderId } = req.body;

View File

@ -1,8 +1,8 @@
<%- include('partials/header') %> <%- include('partials/header') %>
<h1>Trainings</h1> <h1>Training <%= training.datum %></h1>
<form method="GET" action="/"> <form method="GET" action="/">
<label for="training-date">Wählen Sie ein Datum:</label> <label for="training-date">Datum wählen:</label>
<select id="training-date" name="date" onchange="this.form.submit()"> <select id="training-date" name="date" onchange="this.form.submit()">
<% trainingsDates.forEach(date => { %> <% trainingsDates.forEach(date => { %>
<option value="<%= date.rawDatum %>" <%= selectedDate === date.datum ? 'selected' : '' %>> <option value="<%= date.rawDatum %>" <%= selectedDate === date.datum ? 'selected' : '' %>>
@ -12,14 +12,16 @@
</select> </select>
</form> </form>
<% if (training) { %> <% if (training) { %>
<h2> Geräte </h2>
<ul> <ul>
<li>Datum: <%= training.datum %></li> <li>Riege 1: <%= training.geraet_riege_1_name %></li>
<li>Gerät Riege 1: <%= training.geraet_riege_1_name %></li> <li>Riege 2: <%= training.geraet_riege_2_name %></li>
<li>Gerät Riege 2: <%= training.geraet_riege_2_name %></li> <li>Riege 3: <%= training.geraet_riege_3_name %></li>
<li>Gerät Riege 3: <%= training.geraet_riege_3_name %></li> <li>Riege 4: <%= training.geraet_riege_4_name %></li>
<li>Gerät Riege 4: <%= training.geraet_riege_4_name %></li> <li>Riege 5: <%= training.geraet_riege_5_name %></li>
<li>Gerät Riege 5: <%= training.geraet_riege_5_name %></li> </ul>
<li> <ul>
<li>
Aufwärmleiter: Aufwärmleiter:
<% if (training.aufwaermleiter_name) { %> <% if (training.aufwaermleiter_name) { %>
<%= training.aufwaermleiter_name %> <%= training.aufwaermleiter_name %>
@ -62,7 +64,7 @@
<form method="POST" action="/update-training"> <form method="POST" action="/update-training">
<input type="hidden" name="trainingId" value="<%= training.id %>"> <input type="hidden" name="trainingId" value="<%= training.id %>">
<input type="hidden" name="type" value="aufwaermen"> <input type="hidden" name="type" value="aufwaermen">
<select name="aufwaermenId"> <select name="spielId">
<% aufwaermenCandidates.forEach(candidate => { %> <% aufwaermenCandidates.forEach(candidate => { %>
<option value="<%= candidate.id %>"><%= candidate.name %> (<%= Math.floor(candidate.weeks_since_last) %> Wochen)</option> <option value="<%= candidate.id %>"><%= candidate.name %> (<%= Math.floor(candidate.weeks_since_last) %> Wochen)</option>
<% }) %> <% }) %>