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();
const app = express();
const port = 2000;
const port = 2001;
// Middleware
app.use(express.static(path.join(__dirname, 'public')));
@ -19,7 +19,7 @@ app.use(express.urlencoded({ extended: false }));
// Session-Konfiguration
app.use(session({
secret: 'your_secret_key',
secret: process.env.SESSIONSECRET,
resave: false,
saveUninitialized: false,
cookie: { maxAge: 1800000 }
@ -42,12 +42,12 @@ const requireAdmin = (req, res, next) => {
// Email-Konfiguration
const transporter = nodemailer.createTransport({
host: "mail.boergmann.it",
host: process.env.MAILHOST,
port: 465,
secure: true,
auth: {
user: 'klaas@boergmann.it',
pass: 'XDsEXTdAUVkH5=V'
user: process.env.MAILUSER,
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) => {
const { trainingId, type, leaderId } = req.body;

View File

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