Mitglied anlegen ohne Datum, Probetraining speichern und anzeigen
This commit is contained in:
parent
5908e3f5c0
commit
a729c184eb
84
app.js
84
app.js
|
@ -91,10 +91,7 @@ const formatDate = (date) => {
|
|||
};
|
||||
|
||||
// Funktion zum Laden des aktuellen oder letzten Trainings
|
||||
const getTraining = async (selectedDate) => {
|
||||
const today = selectedDate ? new Date(selectedDate) : new Date();
|
||||
const dayOfWeek = today.getDay();
|
||||
|
||||
const getTraining = async (kw) => {
|
||||
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,
|
||||
|
@ -111,10 +108,10 @@ const getTraining = async (selectedDate) => {
|
|||
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.datum <= $1
|
||||
ORDER BY tr.datum DESC
|
||||
WHERE tr.kw <= $1
|
||||
ORDER BY tr.kw DESC
|
||||
LIMIT 1
|
||||
`, [today]);
|
||||
`, [kw]);
|
||||
|
||||
return result.rows[0];
|
||||
};
|
||||
|
@ -138,6 +135,16 @@ const addNewSpiel = async (spielName) => {
|
|||
}
|
||||
};
|
||||
|
||||
function getThursdayOfWeek(week, year) {
|
||||
|
||||
const firstDayOfYear = new Date(year, 0, 1);
|
||||
const dayOfWeek = firstDayOfYear.getDay();
|
||||
const daysUntilFirstThursday = (dayOfWeek <= 4) ? (4 - dayOfWeek) : (11 - dayOfWeek);
|
||||
const daysUntilThursdayOfWeek = (week - 1) * 7 + daysUntilFirstThursday;
|
||||
const thursdayOfWeek = new Date(year, 0, 1 + daysUntilThursdayOfWeek);
|
||||
return thursdayOfWeek;
|
||||
}
|
||||
|
||||
// Funktion zum Laden der vier Leute, die am längsten nicht Aufwärmen oder Spiel geleitet haben
|
||||
const getCandidatesForAufwaermleiter = async () => {
|
||||
const result = await pool.query(`
|
||||
|
@ -161,10 +168,10 @@ const putInRiege = async (riege, teilnehmerID) => {
|
|||
|
||||
if (resultRiege.rows.length > 0) {
|
||||
const resultRiege = await pool.query('UPDATE riegen SET riegennummer = $1 WHERE fremdid_teilnehmende = $2', [riege, teilnehmerID]);
|
||||
console.log("Mitglied ist jetzt in Riege $1", [riege]);
|
||||
log.Info("Mitglied " + teilnehmerID + " ist jetzt in Riege " + riege);
|
||||
} else {
|
||||
const resultRiege = await pool.query('INSERT INTO riegen (fremdid_teilnehmende, riegennummer) VALUES ($1, $2)', [teilnehmerID, riege]);
|
||||
console.log("Mitglied neu in Riege $1 eingefügt.", [riege]);
|
||||
log.Info("Mitglied " + teilnehmerID + " neu in Riege " + riege + " eingefügt.");
|
||||
}}
|
||||
} catch (error) {
|
||||
console.error('Error adding new spiel:', error);
|
||||
|
@ -495,12 +502,15 @@ app.get('/admin', requireAuth, requireAdmin, async (req, res) => {
|
|||
});
|
||||
|
||||
app.post('/new-member', requireAuth, requireAdmin, async (req, res) => {
|
||||
const { vorname, nachname, geburt, riege, adresse } = req.body;
|
||||
const { vorname, nachname, geburt, riege, adresse, probe} = req.body;
|
||||
var geb = "01.01.2024";
|
||||
const name = vorname + ' ' + nachname;
|
||||
console.log(name + ', ' + geburt + ', ' + riege + ', ' + adresse);
|
||||
try {
|
||||
const teilnehmerID = await pool.query('INSERT INTO teilnehmende (name, geburtsdatum, adresse, vorname, nachname) VALUES ($1, $2, $3, $4, $5) RETURNING id', [name, geburt, adresse, vorname, nachname]);
|
||||
console.log(teilnehmerID.rows[0].id);
|
||||
if(geburt){
|
||||
geb = geburt;
|
||||
}
|
||||
const teilnehmerID = await pool.query('INSERT INTO teilnehmende (name, geburtsdatum, adresse, vorname, nachname, probe) VALUES ($1, $2, $3, $4, $5, $6) RETURNING id', [name, geb, adresse, vorname, nachname, probe ? true : false]);
|
||||
log.Info("Mitglied " + name + " durch " + req.session.userName + " angelegt" );
|
||||
putInRiege(riege, teilnehmerID.rows[0].id);
|
||||
res.redirect('/riege');
|
||||
} catch (error) {
|
||||
|
@ -520,38 +530,32 @@ app.get('/training', requireAuth, async (req, res) => {
|
|||
let selectetYear;
|
||||
|
||||
|
||||
if (dateParam) {
|
||||
selectedDate = moment(dateParam, 'DD.MM.YYYY').toDate();
|
||||
} else {
|
||||
selectedDate = moment().toDate();
|
||||
}
|
||||
|
||||
if (kwParam) {
|
||||
selectedKW = kwParam;
|
||||
if (jahrParam) {
|
||||
selectetYear = jahrParam;
|
||||
if (kwParam) {
|
||||
selectedKW = kwParam;
|
||||
} else {
|
||||
if (dateParam) {
|
||||
selectetYear = moment(selectedDate).year();
|
||||
}
|
||||
selectedKW = moment().isoWeek();
|
||||
}
|
||||
} else {
|
||||
selectedKW = moment(selectedDate).isoWeek();
|
||||
selectetYear = moment(selectedDate).year();
|
||||
}
|
||||
const training = await getTraining(selectedDate);
|
||||
|
||||
const trainingsResult = await pool.query('SELECT datum FROM trainings ORDER BY datum ASC');
|
||||
if (jahrParam) {
|
||||
selectedYear = jahrParam;
|
||||
} else {
|
||||
selectedYear = moment().year();
|
||||
}
|
||||
|
||||
const training = await getTraining(selectedKW);
|
||||
|
||||
const anwesendResult = await pool.query('SELECT * FROM anwesend WHERE fid_training = $1', [training.id]);
|
||||
anwesend = anwesendResult.rows;
|
||||
|
||||
const trainingsResult = await pool.query('SELECT kw, jahr FROM trainings ORDER BY kw ASC');
|
||||
const trainingsDates = trainingsResult.rows.map(tr => ({
|
||||
datum: formatDate(tr.datum),
|
||||
rawDatum: tr.datum
|
||||
kw: tr.kw,
|
||||
datum: formatDate(getThursdayOfWeek(tr.kw, tr.jahr))
|
||||
}));
|
||||
|
||||
// Vorheriges Training ermitteln
|
||||
const previousTrainingResult = await pool.query('SELECT * FROM trainings WHERE datum < $1 ORDER BY datum DESC LIMIT 1', [selectedDate]);
|
||||
const nextTrainingResult = await pool.query('SELECT * FROM trainings WHERE datum > $1 ORDER BY datum ASC LIMIT 1', [selectedDate]);
|
||||
const previousTrainingResult = await pool.query('SELECT * FROM trainings WHERE kw < $1 ORDER BY kw DESC LIMIT 1', [selectedKW]);
|
||||
const nextTrainingResult = await pool.query('SELECT * FROM trainings WHERE kw > $1 ORDER BY kw ASC LIMIT 1', [selectedKW]);
|
||||
const previousTraining = previousTrainingResult.rows.length > 0 ? previousTrainingResult.rows[0] : null;
|
||||
const nextTraining = nextTrainingResult.rows.length > 0 ? nextTrainingResult.rows[0] : null;
|
||||
|
||||
|
@ -583,7 +587,7 @@ app.get('/training', requireAuth, async (req, res) => {
|
|||
});
|
||||
|
||||
if (training) {
|
||||
training.datum = formatDate(training.datum);
|
||||
training.datum = getThursdayOfWeek(training.kw, training.jahr);
|
||||
}
|
||||
|
||||
const aufwaermleiterCandidates = await getCandidatesForAufwaermleiter();
|
||||
|
@ -594,7 +598,7 @@ app.get('/training', requireAuth, async (req, res) => {
|
|||
res.render('trainings', {
|
||||
training,
|
||||
trainingsDates,
|
||||
selectedDate: training.datum,
|
||||
selectedKW: training.kw,
|
||||
aufwaermleiterCandidates,
|
||||
spielleiterCandidates,
|
||||
aufwaermenCandidates, // Übergeben der Kandidaten für Aufwärmleiter
|
||||
|
@ -711,7 +715,7 @@ app.post('/set-riege', requireAuth, async (req, res) => {
|
|||
})
|
||||
|
||||
app.post('/update-mitglied', requireAdmin, async (req, res) => {
|
||||
const { type, id, geburt, telid, adresse, name, verbindung, nummer } = req.body;
|
||||
const { type, id, geburt, telid, adresse, name, verbindung, nummer, probe } = req.body;
|
||||
try {
|
||||
if (type == "tel") {
|
||||
console.log('INSERT INTO telefonnummern (fid_teilnehmer, name, verbindung, nummer, stand) VALUES ($1, $2, $3, $4, $5)', [id, name, verbindung, nummer, moment().toDate()]);
|
||||
|
@ -720,7 +724,7 @@ app.post('/update-mitglied', requireAdmin, async (req, res) => {
|
|||
await pool.query('DELETE FROM telefonnummern WHERE id = $1', [telid]);
|
||||
console.log('delete numer $1', [telid]);
|
||||
} else if (type == "adresse") {
|
||||
await pool.query('UPDATE teilnehmende SET geburtsdatum = $1, adresse = $2 WHERE id = $3', [geburt, adresse, id]);
|
||||
await pool.query('UPDATE teilnehmende SET geburtsdatum = $1, adresse = $2, probe = $3 WHERE id = $4', [geburt, adresse, probe ? true : false, id]);
|
||||
}
|
||||
|
||||
res.redirect('/mitglied/' + id);
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
<div class="tab-pane fade show active" id="cont-1" role="tabpanel" aria-labelledby="tab-1">
|
||||
<form method="POST" action="/new-member">
|
||||
Name: <input type="text" id="vorname" placeholder="Vorname" name="vorname">
|
||||
<input type="text" id="nachname" placeholder="Nachname" name="nachname"> </br>
|
||||
<input type="text" id="nachname" placeholder="Nachname" name="nachname"></br>
|
||||
Geburtsdatum: <input type="date" id="geburt" name="geburt"></br>
|
||||
<select name="riege">
|
||||
<option value=1> Riege 1</option>
|
||||
|
@ -27,6 +27,7 @@
|
|||
<option value=5> Riege 5</option>
|
||||
</select></br>
|
||||
Adresse: <input type="text" id="adresse" placeholder="Adresse" name="adresse"></br>
|
||||
Probe: <input type="checkbox" name="probe" value="true"></br>
|
||||
<button type="submit">Speichern</button>
|
||||
</form>
|
||||
|
||||
|
|
|
@ -7,7 +7,9 @@
|
|||
<strong> Geburtsdatum: </strong> <%= birthday.getDate() %>.<%= birthday.getMonth() + 1 %>.<%= birthday.getFullYear() %> (<%= mitglied.age %>)</br>
|
||||
<strong> Adresse: </strong> <%= mitglied.adresse %> </br>
|
||||
<strong> Riege: </strong> <%= (riege == 0) ? 'keine' : riege %> </br>
|
||||
<% if (mitglied.probe) { %> <strong>Probetraining</strong></br> <% } %>
|
||||
<strong> Anwesend: </strong> <%= anwesend %> Mal </br>
|
||||
|
||||
<% numbers.forEach(number => { %>
|
||||
<% if (number.verbindung === 4) { %>
|
||||
<strong> Telefonnummer: </strong> <%= number.nummer %> </br>
|
||||
|
@ -33,7 +35,8 @@
|
|||
Geburtsdatum: <input type="date" id="geburt" name="geburt" value="<%= birthday.getFullYear() %>-<%= ('00' + (birthday.getMonth() + 1)).slice(-2) %>-<%= ('00' + birthday.getDate()).slice(-2) %>"></br>
|
||||
<input type="hidden" name="id" value="<%= id %>">
|
||||
<input type="hidden" name="type" value="adresse">
|
||||
<strong> Adresse: </strong> <input name="adresse" type="text" value="<%= mitglied.adresse %>">
|
||||
<strong> Adresse: </strong> <input name="adresse" type="text" value="<%= mitglied.adresse %>"></br>
|
||||
<strong> Probetraining: </strong> <input type="checkbox" name="probe" value="true" <%= mitglied.probe ? 'checked' : '' %>></br>
|
||||
<button type="submit">Speichern</button>
|
||||
</form>
|
||||
|
||||
|
|
|
@ -2,11 +2,11 @@
|
|||
<h1>
|
||||
<div>
|
||||
<% if (previousTraining) { %>
|
||||
<a href="/training?date=<%= moment(previousTraining.datum).format('DD.MM.YYYY') %>"> < </a>
|
||||
<a href="/training?kw=<%= previousTraining.kw %>"> < </a>
|
||||
<% } %>
|
||||
Training <%= training.datum %>
|
||||
Training <%= moment(training.datum).format('DD.MM.YYYY') %>
|
||||
<% if (nextTraining) { %>
|
||||
<a href="/training?date=<%= moment(nextTraining.datum).format('DD.MM.YYYY') %>"> > </a>
|
||||
<a href="/training?kw=<%= nextTraining.kw %>"> > </a>
|
||||
<% } %>
|
||||
</h1>
|
||||
</div>
|
||||
|
@ -175,10 +175,10 @@
|
|||
<div>
|
||||
<form method="GET" action="/training">
|
||||
<label for="training-date">Datum wählen:</label>
|
||||
<select id="training-date" name="date" onchange="this.form.submit()">
|
||||
<select id="training-date" name="kw" onchange="this.form.submit()">
|
||||
<% trainingsDates.forEach(date => { %>
|
||||
<option value="<%= date.datum %>" <%= selectedDate === date.datum ? 'selected' : '' %>>
|
||||
<%= date.datum %>
|
||||
<option value="<%= date.kw %>" <%= selectedKW === date.kw ? 'selected' : '' %>>
|
||||
<%= date.datum %> %>
|
||||
</option>
|
||||
<% }) %>
|
||||
</select>
|
||||
|
|
Loading…
Reference in New Issue