diff --git a/app.js b/app.js index 6a41ca7..ff9c582 100644 --- a/app.js +++ b/app.js @@ -156,6 +156,31 @@ const getTraining = async (kw, jahr) => { return result.rows[0]; }; +const getTrainingbyID = async (id) => { + const result = await pool.query( + ` + SELECT tr.*, g1.name AS geraet_riege_1_name, g2.name AS geraet_riege_2_name, + g3.name AS geraet_riege_3_name, g4.name AS geraet_riege_4_name, + g5.name AS geraet_riege_5_name, + t1.name AS aufwaermleiter_name, t2.name AS spielleiter_name, + sp1.name AS aufwaermen_name, sp2.name AS spiel_name + FROM trainings tr + LEFT JOIN geraete g1 ON tr.geraet_riege_1 = g1.id + LEFT JOIN geraete g2 ON tr.geraet_riege_2 = g2.id + LEFT JOIN geraete g3 ON tr.geraet_riege_3 = g3.id + LEFT JOIN geraete g4 ON tr.geraet_riege_4 = g4.id + LEFT JOIN geraete g5 ON tr.geraet_riege_5 = g5.id + LEFT JOIN teilnehmende t1 ON tr.aufwaermleiter = t1.id + LEFT JOIN teilnehmende t2 ON tr.spielleiter = t2.id + LEFT JOIN spiele sp1 ON tr.aufwaermen = sp1.id + LEFT JOIN spiele sp2 ON tr.spiel = sp2.id + WHERE tr.id=$1 + `, + [id] + ); + return result.rows[0]; +}; + // Funktion zum Laden aller Spiele const getAllSpiele = async () => { const result = await pool.query(` @@ -670,24 +695,28 @@ app.get("/training", requireAuth, async (req, res) => { let dateParam = req.query.date; let kwParam = req.query.kw; let jahrParam = req.query.jahr; + let idParam = req.query.id; let selectedDate; let selectedKW; let selectetYear; + let training; - if (kwParam) { + if (idParam) { + training = await getTrainingbyID(idParam); + } else if (kwParam) { selectedKW = kwParam; + if (jahrParam) { + selectedYear = jahrParam; + } else { + selectedYear = moment().year(); + } + training = await getTraining(selectedKW, selectedYear); } else { selectedKW = moment().isoWeek(); - } - - if (jahrParam) { - selectedYear = jahrParam; - } else { selectedYear = moment().year(); + training = await getTraining(selectedKW, selectedYear); } - const training = await getTraining(selectedKW, selectedYear); - const anwesendResult = await pool.query( "SELECT * FROM anwesend WHERE fid_training = $1", [training.id] @@ -695,10 +724,12 @@ app.get("/training", requireAuth, async (req, res) => { anwesend = anwesendResult.rows; const anzahl = anwesend.length; const trainingsResult = await pool.query( - "SELECT kw, jahr FROM trainings ORDER BY kw ASC" + "SELECT id, kw, jahr FROM trainings ORDER BY jahr DESC, kw DESC" ); const trainingsDates = trainingsResult.rows.map((tr) => ({ kw: tr.kw, + id: tr.id, + jahr: tr.jahr, datum: formatDate(getdayOfWeek(tr.kw, tr.jahr)), })); @@ -1191,5 +1222,6 @@ app.post("/feature", requireAdmin, async (req, res) => { }); const server = app.listen(port, "0.0.0.0", () => { + console.log(`Server is running on ${process.env.HOST}:${port}/`); log.Info(`Server is running on ${process.env.HOST}:${port}/`); }); diff --git a/views/trainings.ejs b/views/trainings.ejs index c9a1fdf..e93896f 100644 --- a/views/trainings.ejs +++ b/views/trainings.ejs @@ -1,12 +1,12 @@ <%- include('partials/header') %>

- <% if (previousTraining) { %> - < + <% if (previousTraining) { %> + < <% } %> Training <%= moment(training.datum).format('DD.MM.YYYY') %> <% if (nextTraining) { %> - > + > <% } %>

@@ -272,9 +272,9 @@
- <% trainingsDates.forEach(date => { %> - <% }) %> diff --git a/views/trainings_riegen.ejs b/views/trainings_riegen.ejs index d503afc..086ddcc 100644 --- a/views/trainings_riegen.ejs +++ b/views/trainings_riegen.ejs @@ -2,11 +2,11 @@

<% if (previousTraining) { %> - < + < <% } %> Training <%= moment(training.datum).format('DD.MM.YYYY') %> <% if (nextTraining) { %> - > + > <% } %>

@@ -387,9 +387,9 @@
- <% trainingsDates.forEach(date => { %> - <% }) %>