Mitglied anlegen ohne Datum, Probetraining speichern und anzeigen
This commit is contained in:
parent
5908e3f5c0
commit
a729c184eb
80
app.js
80
app.js
|
@ -91,10 +91,7 @@ const formatDate = (date) => {
|
||||||
};
|
};
|
||||||
|
|
||||||
// Funktion zum Laden des aktuellen oder letzten Trainings
|
// Funktion zum Laden des aktuellen oder letzten Trainings
|
||||||
const getTraining = async (selectedDate) => {
|
const getTraining = async (kw) => {
|
||||||
const today = selectedDate ? new Date(selectedDate) : new Date();
|
|
||||||
const dayOfWeek = today.getDay();
|
|
||||||
|
|
||||||
const result = await pool.query(`
|
const result = await pool.query(`
|
||||||
SELECT tr.*, g1.name AS geraet_riege_1_name, g2.name AS geraet_riege_2_name,
|
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,
|
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 teilnehmende t2 ON tr.spielleiter = t2.id
|
||||||
LEFT JOIN spiele sp1 ON tr.aufwaermen = sp1.id
|
LEFT JOIN spiele sp1 ON tr.aufwaermen = sp1.id
|
||||||
LEFT JOIN spiele sp2 ON tr.spiel = sp2.id
|
LEFT JOIN spiele sp2 ON tr.spiel = sp2.id
|
||||||
WHERE tr.datum <= $1
|
WHERE tr.kw <= $1
|
||||||
ORDER BY tr.datum DESC
|
ORDER BY tr.kw DESC
|
||||||
LIMIT 1
|
LIMIT 1
|
||||||
`, [today]);
|
`, [kw]);
|
||||||
|
|
||||||
return result.rows[0];
|
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
|
// Funktion zum Laden der vier Leute, die am längsten nicht Aufwärmen oder Spiel geleitet haben
|
||||||
const getCandidatesForAufwaermleiter = async () => {
|
const getCandidatesForAufwaermleiter = async () => {
|
||||||
const result = await pool.query(`
|
const result = await pool.query(`
|
||||||
|
@ -161,10 +168,10 @@ const putInRiege = async (riege, teilnehmerID) => {
|
||||||
|
|
||||||
if (resultRiege.rows.length > 0) {
|
if (resultRiege.rows.length > 0) {
|
||||||
const resultRiege = await pool.query('UPDATE riegen SET riegennummer = $1 WHERE fremdid_teilnehmende = $2', [riege, teilnehmerID]);
|
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 {
|
} else {
|
||||||
const resultRiege = await pool.query('INSERT INTO riegen (fremdid_teilnehmende, riegennummer) VALUES ($1, $2)', [teilnehmerID, riege]);
|
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) {
|
} catch (error) {
|
||||||
console.error('Error adding new spiel:', 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) => {
|
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;
|
const name = vorname + ' ' + nachname;
|
||||||
console.log(name + ', ' + geburt + ', ' + riege + ', ' + adresse);
|
|
||||||
try {
|
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]);
|
if(geburt){
|
||||||
console.log(teilnehmerID.rows[0].id);
|
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);
|
putInRiege(riege, teilnehmerID.rows[0].id);
|
||||||
res.redirect('/riege');
|
res.redirect('/riege');
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
@ -520,38 +530,32 @@ app.get('/training', requireAuth, async (req, res) => {
|
||||||
let selectetYear;
|
let selectetYear;
|
||||||
|
|
||||||
|
|
||||||
if (dateParam) {
|
|
||||||
selectedDate = moment(dateParam, 'DD.MM.YYYY').toDate();
|
|
||||||
} else {
|
|
||||||
selectedDate = moment().toDate();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (kwParam) {
|
if (kwParam) {
|
||||||
selectedKW = kwParam;
|
selectedKW = kwParam;
|
||||||
if (jahrParam) {
|
|
||||||
selectetYear = jahrParam;
|
|
||||||
} else {
|
} else {
|
||||||
if (dateParam) {
|
selectedKW = moment().isoWeek();
|
||||||
selectetYear = moment(selectedDate).year();
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
} 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]);
|
const anwesendResult = await pool.query('SELECT * FROM anwesend WHERE fid_training = $1', [training.id]);
|
||||||
anwesend = anwesendResult.rows;
|
anwesend = anwesendResult.rows;
|
||||||
|
|
||||||
|
const trainingsResult = await pool.query('SELECT kw, jahr FROM trainings ORDER BY kw ASC');
|
||||||
const trainingsDates = trainingsResult.rows.map(tr => ({
|
const trainingsDates = trainingsResult.rows.map(tr => ({
|
||||||
datum: formatDate(tr.datum),
|
kw: tr.kw,
|
||||||
rawDatum: tr.datum
|
datum: formatDate(getThursdayOfWeek(tr.kw, tr.jahr))
|
||||||
}));
|
}));
|
||||||
|
|
||||||
// Vorheriges Training ermitteln
|
// Vorheriges Training ermitteln
|
||||||
const previousTrainingResult = await pool.query('SELECT * FROM trainings WHERE datum < $1 ORDER BY datum DESC 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 datum > $1 ORDER BY datum ASC LIMIT 1', [selectedDate]);
|
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 previousTraining = previousTrainingResult.rows.length > 0 ? previousTrainingResult.rows[0] : null;
|
||||||
const nextTraining = nextTrainingResult.rows.length > 0 ? nextTrainingResult.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) {
|
if (training) {
|
||||||
training.datum = formatDate(training.datum);
|
training.datum = getThursdayOfWeek(training.kw, training.jahr);
|
||||||
}
|
}
|
||||||
|
|
||||||
const aufwaermleiterCandidates = await getCandidatesForAufwaermleiter();
|
const aufwaermleiterCandidates = await getCandidatesForAufwaermleiter();
|
||||||
|
@ -594,7 +598,7 @@ app.get('/training', requireAuth, async (req, res) => {
|
||||||
res.render('trainings', {
|
res.render('trainings', {
|
||||||
training,
|
training,
|
||||||
trainingsDates,
|
trainingsDates,
|
||||||
selectedDate: training.datum,
|
selectedKW: training.kw,
|
||||||
aufwaermleiterCandidates,
|
aufwaermleiterCandidates,
|
||||||
spielleiterCandidates,
|
spielleiterCandidates,
|
||||||
aufwaermenCandidates, // Übergeben der Kandidaten für Aufwärmleiter
|
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) => {
|
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 {
|
try {
|
||||||
if (type == "tel") {
|
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()]);
|
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]);
|
await pool.query('DELETE FROM telefonnummern WHERE id = $1', [telid]);
|
||||||
console.log('delete numer $1', [telid]);
|
console.log('delete numer $1', [telid]);
|
||||||
} else if (type == "adresse") {
|
} 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);
|
res.redirect('/mitglied/' + id);
|
||||||
|
|
|
@ -27,6 +27,7 @@
|
||||||
<option value=5> Riege 5</option>
|
<option value=5> Riege 5</option>
|
||||||
</select></br>
|
</select></br>
|
||||||
Adresse: <input type="text" id="adresse" placeholder="Adresse" name="adresse"></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>
|
<button type="submit">Speichern</button>
|
||||||
</form>
|
</form>
|
||||||
|
|
||||||
|
|
|
@ -7,7 +7,9 @@
|
||||||
<strong> Geburtsdatum: </strong> <%= birthday.getDate() %>.<%= birthday.getMonth() + 1 %>.<%= birthday.getFullYear() %> (<%= mitglied.age %>)</br>
|
<strong> Geburtsdatum: </strong> <%= birthday.getDate() %>.<%= birthday.getMonth() + 1 %>.<%= birthday.getFullYear() %> (<%= mitglied.age %>)</br>
|
||||||
<strong> Adresse: </strong> <%= mitglied.adresse %> </br>
|
<strong> Adresse: </strong> <%= mitglied.adresse %> </br>
|
||||||
<strong> Riege: </strong> <%= (riege == 0) ? 'keine' : riege %> </br>
|
<strong> Riege: </strong> <%= (riege == 0) ? 'keine' : riege %> </br>
|
||||||
|
<% if (mitglied.probe) { %> <strong>Probetraining</strong></br> <% } %>
|
||||||
<strong> Anwesend: </strong> <%= anwesend %> Mal </br>
|
<strong> Anwesend: </strong> <%= anwesend %> Mal </br>
|
||||||
|
|
||||||
<% numbers.forEach(number => { %>
|
<% numbers.forEach(number => { %>
|
||||||
<% if (number.verbindung === 4) { %>
|
<% if (number.verbindung === 4) { %>
|
||||||
<strong> Telefonnummer: </strong> <%= number.nummer %> </br>
|
<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>
|
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="id" value="<%= id %>">
|
||||||
<input type="hidden" name="type" value="adresse">
|
<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>
|
<button type="submit">Speichern</button>
|
||||||
</form>
|
</form>
|
||||||
|
|
||||||
|
|
|
@ -2,11 +2,11 @@
|
||||||
<h1>
|
<h1>
|
||||||
<div>
|
<div>
|
||||||
<% if (previousTraining) { %>
|
<% 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) { %>
|
<% if (nextTraining) { %>
|
||||||
<a href="/training?date=<%= moment(nextTraining.datum).format('DD.MM.YYYY') %>"> > </a>
|
<a href="/training?kw=<%= nextTraining.kw %>"> > </a>
|
||||||
<% } %>
|
<% } %>
|
||||||
</h1>
|
</h1>
|
||||||
</div>
|
</div>
|
||||||
|
@ -175,10 +175,10 @@
|
||||||
<div>
|
<div>
|
||||||
<form method="GET" action="/training">
|
<form method="GET" action="/training">
|
||||||
<label for="training-date">Datum wählen:</label>
|
<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 => { %>
|
<% trainingsDates.forEach(date => { %>
|
||||||
<option value="<%= date.datum %>" <%= selectedDate === date.datum ? 'selected' : '' %>>
|
<option value="<%= date.kw %>" <%= selectedKW === date.kw ? 'selected' : '' %>>
|
||||||
<%= date.datum %>
|
<%= date.datum %> %>
|
||||||
</option>
|
</option>
|
||||||
<% }) %>
|
<% }) %>
|
||||||
</select>
|
</select>
|
||||||
|
|
Loading…
Reference in New Issue