beautifyed
This commit is contained in:
parent
ef495986a7
commit
264dcebf6c
416
app.js
416
app.js
|
@ -16,11 +16,11 @@ const options = {
|
||||||
folderPath: './logs/',
|
folderPath: './logs/',
|
||||||
dateBasedFileNaming: true,
|
dateBasedFileNaming: true,
|
||||||
fileNamePrefix: 'DailyLogs_',
|
fileNamePrefix: 'DailyLogs_',
|
||||||
fileNameExtension: '.log',
|
fileNameExtension: '.log',
|
||||||
dateFormat: 'YYYY_MM_D',
|
dateFormat: 'YYYY_MM_D',
|
||||||
timeFormat: 'h:mm:ss A',
|
timeFormat: 'h:mm:ss A',
|
||||||
}
|
}
|
||||||
log.SetUserOptions(options);
|
log.SetUserOptions(options);
|
||||||
|
|
||||||
|
|
||||||
// Middleware
|
// Middleware
|
||||||
|
@ -94,7 +94,7 @@ const getTraining = async (selectedDate) => {
|
||||||
const today = selectedDate ? new Date(selectedDate) : new Date();
|
const today = selectedDate ? new Date(selectedDate) : new Date();
|
||||||
const dayOfWeek = today.getDay();
|
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,
|
||||||
g5.name AS geraet_riege_5_name,
|
g5.name AS geraet_riege_5_name,
|
||||||
|
@ -115,27 +115,27 @@ const getTraining = async (selectedDate) => {
|
||||||
LIMIT 1
|
LIMIT 1
|
||||||
`, [today]);
|
`, [today]);
|
||||||
|
|
||||||
return result.rows[0];
|
return result.rows[0];
|
||||||
};
|
};
|
||||||
|
|
||||||
// Funktion zum Laden aller Spiele
|
// Funktion zum Laden aller Spiele
|
||||||
const getAllSpiele = async () => {
|
const getAllSpiele = async () => {
|
||||||
const result = await pool.query(`
|
const result = await pool.query(`
|
||||||
SELECT * FROM spiele ORDER BY name ASC;
|
SELECT * FROM spiele ORDER BY name ASC;
|
||||||
`);
|
`);
|
||||||
return result.rows;
|
return result.rows;
|
||||||
};
|
};
|
||||||
|
|
||||||
// Funktion zum Hinzufügen eines neuen Spiels, falls es noch nicht existiert
|
// Funktion zum Hinzufügen eines neuen Spiels, falls es noch nicht existiert
|
||||||
const addNewSpiel = async (spielName) => {
|
const addNewSpiel = async (spielName) => {
|
||||||
try {
|
try {
|
||||||
const result = await pool.query('INSERT INTO spiele (name) VALUES ($1) RETURNING id', [spielName]);
|
const result = await pool.query('INSERT INTO spiele (name) VALUES ($1) RETURNING id', [spielName]);
|
||||||
return result.rows[0].id;
|
return result.rows[0].id;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Error adding new spiel:', error);
|
console.error('Error adding new spiel:', error);
|
||||||
throw error;
|
throw error;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// 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 () => {
|
||||||
|
@ -156,7 +156,7 @@ const putInRiege = async (riege, teilnehmerID) => {
|
||||||
const resultRiege = await pool.query('SELECT * FROM riegen WHERE fremdid_teilnehmende = $1;', [teilnehmerID]);
|
const resultRiege = await pool.query('SELECT * FROM riegen WHERE fremdid_teilnehmende = $1;', [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]);
|
console.log("Mitglied ist jetzt in Riege $1", [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]);
|
||||||
|
@ -184,23 +184,23 @@ const getCandidatesForSpielleiter = async () => {
|
||||||
|
|
||||||
// Funktion zum Laden der Riegenteilnehmer absteigend nach Alter sortiert
|
// Funktion zum Laden der Riegenteilnehmer absteigend nach Alter sortiert
|
||||||
const getRiegenMitgliederSortedByAge = async () => {
|
const getRiegenMitgliederSortedByAge = async () => {
|
||||||
const result = await pool.query(`
|
const result = await pool.query(`
|
||||||
SELECT r.riegennummer, t.name, t.alter
|
SELECT r.riegennummer, t.name, t.alter
|
||||||
FROM riegen r
|
FROM riegen r
|
||||||
JOIN teilnehmende t ON r.fremdid_teilnehmende = t.id
|
JOIN teilnehmende t ON r.fremdid_teilnehmende = t.id
|
||||||
ORDER BY r.riegennummer, t.alter DESC
|
ORDER BY r.riegennummer, t.alter DESC
|
||||||
`);
|
`);
|
||||||
return result.rows;
|
return result.rows;
|
||||||
};
|
};
|
||||||
|
|
||||||
const getAnwesenheit = function (id, anwesend) {
|
const getAnwesenheit = function (id, anwesend) {
|
||||||
for (let item of anwesend) {
|
for (let item of anwesend) {
|
||||||
if (item.fid_teilnehmer === id) {
|
if (item.fid_teilnehmer === id) {
|
||||||
return true;
|
return true;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return false;
|
}
|
||||||
};
|
return false;
|
||||||
|
};
|
||||||
|
|
||||||
// Registrierung
|
// Registrierung
|
||||||
app.post('/register', async (req, res) => {
|
app.post('/register', async (req, res) => {
|
||||||
|
@ -220,25 +220,25 @@ app.post('/register', async (req, res) => {
|
||||||
if (error) {
|
if (error) {
|
||||||
console.error('Error sending email:', error);
|
console.error('Error sending email:', error);
|
||||||
const message = 'Error sending Mail:' + error;
|
const message = 'Error sending Mail:' + error;
|
||||||
res.render('error', {session: req.session, message});
|
res.render('error', { session: req.session, message });
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
res.render('error', {session: req.session, message});
|
res.render('error', { session: req.session, message });
|
||||||
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Error registering user:', error);
|
console.error('Error registering user:', error);
|
||||||
const message = 'Error registering user:' + error;
|
const message = 'Error registering user:' + error;
|
||||||
res.render('error', {session: req.session, message});
|
res.render('error', { session: req.session, message });
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// Login
|
// Login
|
||||||
app.post('/login', async (req, res) => {
|
app.post('/login', async (req, res) => {
|
||||||
const { username, password } = req.body;
|
const { username, password } = req.body;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const userResult = await pool.query("SELECT *, CASE WHEN admin_temp IS NOT NULL AND (now() - admin_temp) > interval '22 hours' THEN 'expired' ELSE 'valid' END AS admin_status FROM users WHERE username = $1", [ username]);
|
const userResult = await pool.query("SELECT *, CASE WHEN admin_temp IS NOT NULL AND (now() - admin_temp) > interval '22 hours' THEN 'expired' ELSE 'valid' END AS admin_status FROM users WHERE username = $1", [username]);
|
||||||
if (userResult.rows.length > 0) {
|
if (userResult.rows.length > 0) {
|
||||||
const user = userResult.rows[0];
|
const user = userResult.rows[0];
|
||||||
const match = await bcrypt.compare(password, user.password);
|
const match = await bcrypt.compare(password, user.password);
|
||||||
|
@ -248,36 +248,36 @@ app.post('/login', async (req, res) => {
|
||||||
req.session.userName = user.username;
|
req.session.userName = user.username;
|
||||||
req.session.activeRiege = 1;
|
req.session.activeRiege = 1;
|
||||||
req.session.activeTab = 'geraete';
|
req.session.activeTab = 'geraete';
|
||||||
req.session.message = [ title = '', message = '', type = 'none' ];
|
req.session.message = [title = '', message = '', type = 'none'];
|
||||||
log.Info(username + ' ' + password);
|
log.Info(username + ' ' + password);
|
||||||
if (user.admin_status === 'expired') {
|
if (user.admin_status === 'expired') {
|
||||||
await pool.query('UPDATE users SET role = $1, admin_temp = NULL WHERE id = $2', ['user', user.id]);
|
await pool.query('UPDATE users SET role = $1, admin_temp = NULL WHERE id = $2', ['user', user.id]);
|
||||||
req.session.role='user';
|
req.session.role = 'user';
|
||||||
} else {
|
} else {
|
||||||
req.session.role=user.role;
|
req.session.role = user.role;
|
||||||
}
|
}
|
||||||
res.redirect('/training');
|
res.redirect('/training');
|
||||||
} else {
|
} else {
|
||||||
res.redirect('/freischaltung')
|
res.redirect('/freischaltung')
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
const message = 'Falscher Benutzername oder falsches Passwort';
|
const message = 'Falscher Benutzername oder falsches Passwort';
|
||||||
res.render('login', {session: req.session, username, message});
|
res.render('login', { session: req.session, username, message });
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
const message = 'Falscher Benutzername oder falsches Passwort';
|
const message = 'Falscher Benutzername oder falsches Passwort';
|
||||||
res.render('login', {session: req.session, username, message});
|
res.render('login', { session: req.session, username, message });
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Error logging in:', error);
|
console.error('Error logging in:', error);
|
||||||
const message = 'Error logging in:' + error;
|
const message = 'Error logging in:' + error;
|
||||||
res.render('error', {session: req.session, message});
|
res.render('error', { session: req.session, message });
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
//Wird angezeigt, wenn ein nicht freigeschalteter User sich anmelden will.
|
//Wird angezeigt, wenn ein nicht freigeschalteter User sich anmelden will.
|
||||||
app.get('/freischaltung', async (req, res) => {
|
app.get('/freischaltung', async (req, res) => {
|
||||||
res.render('freischaltung', { session: req.session});
|
res.render('freischaltung', { session: req.session });
|
||||||
})
|
})
|
||||||
|
|
||||||
// Logout
|
// Logout
|
||||||
|
@ -294,38 +294,40 @@ app.get('/logout', (req, res) => {
|
||||||
app.post('/userrights', requireAuth, requireAdmin, async (req, res) => {
|
app.post('/userrights', requireAuth, requireAdmin, async (req, res) => {
|
||||||
const { userId, type } = req.body;
|
const { userId, type } = req.body;
|
||||||
try {
|
try {
|
||||||
if (type === 'activate'){
|
if (type === 'activate') {
|
||||||
await pool.query('UPDATE users SET is_active = TRUE WHERE id = $1', [userId]);
|
await pool.query('UPDATE users SET is_active = TRUE WHERE id = $1', [userId]);
|
||||||
const userResult = await pool.query('SELECT * FROM users WHERE id = $1', [userId]);
|
const userResult = await pool.query('SELECT * FROM users WHERE id = $1', [userId]);
|
||||||
if (userResult.rows.length > 0) {
|
if (userResult.rows.length > 0) {
|
||||||
if (userResult.rows[0].email){
|
if (userResult.rows[0].email) {
|
||||||
const mailOptions = {
|
const mailOptions = {
|
||||||
to: userResult.rows[0].email,
|
to: userResult.rows[0].email,
|
||||||
from: 'admin@boergmann.it',
|
from: 'admin@boergmann.it',
|
||||||
subject: 'Freischaltung',
|
subject: 'Freischaltung',
|
||||||
text: `Hallo ${userResult.rows[0].username}, du wurdest soeben freigeschaltet.`
|
text: `Hallo ${userResult.rows[0].username}, du wurdest soeben freigeschaltet.`
|
||||||
};
|
};
|
||||||
|
|
||||||
transporter.sendMail(mailOptions, (error) => {
|
transporter.sendMail(mailOptions, (error) => {
|
||||||
if (error) {
|
if (error) {
|
||||||
console.error('Error sending email:', error);
|
console.error('Error sending email:', error);
|
||||||
const message = 'Error sending Mail:' + error;
|
const message = 'Error sending Mail:' + error;
|
||||||
res.render('error', {session: req.session, message});
|
res.render('error', { session: req.session, message });
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
})}}
|
} else if (type === 'admin') {
|
||||||
} else if (type === 'admin') {
|
await pool.query('UPDATE users SET role = $1 WHERE id = $2', ['admin', userId]);
|
||||||
await pool.query('UPDATE users SET role = $1 WHERE id = $2', ['admin', userId]);
|
}
|
||||||
}
|
else if (type === 'admint') {
|
||||||
else if (type === 'admint') {
|
await pool.query('UPDATE users SET role = $1, admin_temp = $2 WHERE id = $3', ['admin', moment().toDate(), userId]);
|
||||||
await pool.query('UPDATE users SET role = $1, admin_temp = $2 WHERE id = $3', ['admin', moment().toDate() , userId]);
|
} else if (type === 'delete') {
|
||||||
} else if (type === 'delete') {
|
await pool.query('DELETE FROM users WHERE id = $1', [userId]);
|
||||||
await pool.query('DELETE FROM users WHERE id = $1', [userId]);
|
}
|
||||||
}
|
|
||||||
res.redirect('/admin');
|
res.redirect('/admin');
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Error activating user:', error);
|
console.error('Error activating user:', error);
|
||||||
const message = 'Error activating user:' + error;
|
const message = 'Error activating user:' + error;
|
||||||
res.render('error', {session: req.session, message});
|
res.render('error', { session: req.session, message });
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -338,7 +340,7 @@ app.post('/send-password', async (req, res) => {
|
||||||
const user = userResult.rows[0];
|
const user = userResult.rows[0];
|
||||||
const token = crypto.randomBytes(20).toString('hex');
|
const token = crypto.randomBytes(20).toString('hex');
|
||||||
const resetLink = `http://tkd.boergmann.it/reset-password/${token}`;
|
const resetLink = `http://tkd.boergmann.it/reset-password/${token}`;
|
||||||
await pool.query('UPDATE users SET reset_password_token = $1, reset_password_expires = $2 WHERE id = $3', [token, selectedDate = moment().add(1,'d').toDate() , user.id]);
|
await pool.query('UPDATE users SET reset_password_token = $1, reset_password_expires = $2 WHERE id = $3', [token, selectedDate = moment().add(1, 'd').toDate(), user.id]);
|
||||||
|
|
||||||
const mailOptions = {
|
const mailOptions = {
|
||||||
to: user.email,
|
to: user.email,
|
||||||
|
@ -351,25 +353,25 @@ app.post('/send-password', async (req, res) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
console.error('Error sending email:', err);
|
console.error('Error sending email:', err);
|
||||||
const message = 'Error sending Mail:' + error;
|
const message = 'Error sending Mail:' + error;
|
||||||
res.render('error', {session: req.session, message});
|
res.render('error', { session: req.session, message });
|
||||||
} else {
|
} else {
|
||||||
const message = 'Password reset link sent';
|
const message = 'Password reset link sent';
|
||||||
res.render('error', {session: req.session, message});
|
res.render('error', { session: req.session, message });
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
const message = 'Email not found';
|
const message = 'Email not found';
|
||||||
res.render('error', {session: req.session, message});
|
res.render('error', { session: req.session, message });
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Error in forgot-password:', error);
|
console.error('Error in forgot-password:', error);
|
||||||
const message = 'Error in forgot-password';
|
const message = 'Error in forgot-password';
|
||||||
res.render('error', {session: req.session, message});
|
res.render('error', { session: req.session, message });
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
app.get('/forgot-password', async (req, res) => {
|
app.get('/forgot-password', async (req, res) => {
|
||||||
res.render('forgot-password', {session: req.session})
|
res.render('forgot-password', { session: req.session })
|
||||||
})
|
})
|
||||||
|
|
||||||
// Passwort zurücksetzen
|
// Passwort zurücksetzen
|
||||||
|
@ -381,12 +383,12 @@ app.get('/reset-password/:token', async (req, res) => {
|
||||||
res.render('reset-password', { token }); // Stelle sicher, dass es eine reset-password.ejs gibt
|
res.render('reset-password', { token }); // Stelle sicher, dass es eine reset-password.ejs gibt
|
||||||
} else {
|
} else {
|
||||||
const message = 'Token ungültig oder abgelaufen';
|
const message = 'Token ungültig oder abgelaufen';
|
||||||
res.render('error', {session: req.session, message});
|
res.render('error', { session: req.session, message });
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Error in reset-password:', error);
|
console.error('Error in reset-password:', error);
|
||||||
const message = 'Error in reset-password';
|
const message = 'Error in reset-password';
|
||||||
res.render('error', {session: req.session, message});
|
res.render('error', { session: req.session, message });
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -402,18 +404,18 @@ app.post('/reset-password/:token', async (req, res) => {
|
||||||
res.redirect('/login');
|
res.redirect('/login');
|
||||||
} else {
|
} else {
|
||||||
const message = 'Token ungültig oder abgelaufen';
|
const message = 'Token ungültig oder abgelaufen';
|
||||||
res.render('error', {session: req.session, message});
|
res.render('error', { session: req.session, message });
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Error in reset-password:', error);
|
console.error('Error in reset-password:', error);
|
||||||
const message = 'Error in reset-password';
|
const message = 'Error in reset-password';
|
||||||
res.render('error', {session: req.session, message});
|
res.render('error', { session: req.session, message });
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// Profilseite
|
// Profilseite
|
||||||
app.get('/profile', requireAuth, (req, res) => {
|
app.get('/profile', requireAuth, (req, res) => {
|
||||||
res.render('profile', { session: req.session}); // Stelle sicher, dass es eine profile.ejs gibt
|
res.render('profile', { session: req.session }); // Stelle sicher, dass es eine profile.ejs gibt
|
||||||
});
|
});
|
||||||
|
|
||||||
app.post('/profile', requireAuth, async (req, res) => {
|
app.post('/profile', requireAuth, async (req, res) => {
|
||||||
|
@ -430,7 +432,7 @@ app.post('/profile', requireAuth, async (req, res) => {
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Error updating profile:', error);
|
console.error('Error updating profile:', error);
|
||||||
const message = 'Error updating profile:' + error;
|
const message = 'Error updating profile:' + error;
|
||||||
res.render('error', {session: req.session, message});
|
res.render('error', { session: req.session, message });
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -440,33 +442,33 @@ app.post('/update-training', requireAuth, async (req, res) => {
|
||||||
let spielId;
|
let spielId;
|
||||||
|
|
||||||
const spiel = await pool.query(`SELECT * FROM spiele WHERE name = $1`, [spielName]);
|
const spiel = await pool.query(`SELECT * FROM spiele WHERE name = $1`, [spielName]);
|
||||||
|
|
||||||
if (spiel.rows.length > 0) {
|
if (spiel.rows.length > 0) {
|
||||||
spielId = spiel.rows[0].id;
|
spielId = spiel.rows[0].id;
|
||||||
} else {
|
} else {
|
||||||
const newSpiel = await pool.query('INSERT INTO spiele (name) VALUES ($1) RETURNING id', [spielName]);
|
const newSpiel = await pool.query('INSERT INTO spiele (name) VALUES ($1) RETURNING id', [spielName]);
|
||||||
spielId = newSpiel.rows[0].id;
|
spielId = newSpiel.rows[0].id;
|
||||||
req.session.message = [title = 'Neues Spiel', body = 'Das Spiel ${ spielName } wurde angelegt.', type = 'Success'];
|
req.session.message = [title = 'Neues Spiel', body = 'Das Spiel ${ spielName } wurde angelegt.', type = 'Success'];
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (type === 'spiel') {
|
if (type === 'spiel') {
|
||||||
await pool.query('UPDATE trainings SET spiel = $1 WHERE id = $2', [ spielId, trainingId ]);
|
await pool.query('UPDATE trainings SET spiel = $1 WHERE id = $2', [spielId, trainingId]);
|
||||||
} else if (type === 'aufwaermen') {
|
} else if (type === 'aufwaermen') {
|
||||||
await pool.query('UPDATE trainings SET aufwaermen = $1 WHERE id = $2', [ spielId, trainingId ]);
|
await pool.query('UPDATE trainings SET aufwaermen = $1 WHERE id = $2', [spielId, trainingId]);
|
||||||
}
|
}
|
||||||
|
|
||||||
res.redirect('/training');
|
res.redirect('/training');
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(error);
|
console.error(error);
|
||||||
const message = 'Error:' + error;
|
const message = 'Error:' + error;
|
||||||
res.render('error', {session: req.session, message});
|
res.render('error', { session: req.session, message });
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
app.post('/update-leader', requireAuth , async (req, res) => {
|
app.post('/update-leader', requireAuth, async (req, res) => {
|
||||||
const { trainingId, type, leaderId } = req.body;
|
const { trainingId, type, leaderId } = req.body;
|
||||||
req.session.activeTab = 'spiel';
|
req.session.activeTab = 'spiel';
|
||||||
try {
|
try {
|
||||||
if (type === 'aufwaermleiter') {
|
if (type === 'aufwaermleiter') {
|
||||||
await pool.query('UPDATE trainings SET aufwaermleiter = $1 WHERE id = $2', [leaderId, trainingId]);
|
await pool.query('UPDATE trainings SET aufwaermleiter = $1 WHERE id = $2', [leaderId, trainingId]);
|
||||||
|
@ -477,7 +479,7 @@ req.session.activeTab = 'spiel';
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(error);
|
console.error(error);
|
||||||
const message = 'Error:' + error;
|
const message = 'Error:' + error;
|
||||||
res.render('error', {session: req.session, message});
|
res.render('error', { session: req.session, message });
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -487,19 +489,19 @@ app.get('/admin', requireAuth, requireAdmin, async (req, res) => {
|
||||||
res.render('admin', { users: usersResult.rows, session: req.session }); // Stelle sicher, dass es eine admin.ejs gibt
|
res.render('admin', { users: usersResult.rows, session: req.session }); // Stelle sicher, dass es eine admin.ejs gibt
|
||||||
});
|
});
|
||||||
|
|
||||||
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 } = req.body;
|
||||||
const name = vorname + ' ' + nachname;
|
const name = vorname + ' ' + nachname;
|
||||||
console.log(name + ', ' + geburt + ', ' + riege + ', ' + adresse);
|
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]);
|
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);
|
console.log(teilnehmerID.rows[0].id);
|
||||||
putInRiege(riege, teilnehmerID.rows[0].id);
|
putInRiege(riege, teilnehmerID.rows[0].id);
|
||||||
res.redirect('/riege');
|
res.redirect('/riege');
|
||||||
}catch (error) {
|
} catch (error) {
|
||||||
const message = 'Error:' + error;
|
const message = 'Error:' + error;
|
||||||
res.render('error', {session: req.session, message});
|
res.render('error', { session: req.session, message });
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
// Teilnehmer_innen
|
// Teilnehmer_innen
|
||||||
|
@ -511,10 +513,10 @@ app.get('/training', requireAuth, async (req, res) => {
|
||||||
let selectedDate;
|
let selectedDate;
|
||||||
let selectedKW;
|
let selectedKW;
|
||||||
let selectetYear;
|
let selectetYear;
|
||||||
|
|
||||||
|
|
||||||
if (dateParam) {
|
if (dateParam) {
|
||||||
selectedDate = moment(dateParam, 'DD.MM.YYYY').toDate();
|
selectedDate = moment(dateParam, 'DD.MM.YYYY').toDate();
|
||||||
} else {
|
} else {
|
||||||
selectedDate = moment().toDate();
|
selectedDate = moment().toDate();
|
||||||
}
|
}
|
||||||
|
@ -528,53 +530,53 @@ app.get('/training', requireAuth, async (req, res) => {
|
||||||
selectetYear = moment(selectedDate).year();
|
selectetYear = moment(selectedDate).year();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
selectedKW = moment(selectedDate).isoWeek();
|
selectedKW = moment(selectedDate).isoWeek();
|
||||||
selectetYear = moment(selectedDate).year();
|
selectetYear = moment(selectedDate).year();
|
||||||
}
|
}
|
||||||
console.log(selectedKW + ' ' + selectetYear);
|
console.log(selectedKW + ' ' + selectetYear);
|
||||||
const training =await getTraining(selectedDate);
|
const training = await getTraining(selectedDate);
|
||||||
|
|
||||||
const trainingsResult = await pool.query('SELECT datum FROM trainings ORDER BY datum ASC');
|
const trainingsResult = await pool.query('SELECT datum FROM trainings ORDER BY datum ASC');
|
||||||
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 trainingsDates = trainingsResult.rows.map(tr => ({
|
const trainingsDates = trainingsResult.rows.map(tr => ({
|
||||||
datum: formatDate(tr.datum),
|
datum: formatDate(tr.datum),
|
||||||
rawDatum: tr.datum
|
rawDatum: tr.datum
|
||||||
}));
|
}));
|
||||||
|
|
||||||
// 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 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 nextTrainingResult = await pool.query('SELECT * FROM trainings WHERE datum > $1 ORDER BY datum ASC LIMIT 1', [selectedDate]);
|
||||||
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;
|
||||||
|
|
||||||
// Abrufen der Riegendaten einschließlich der Teilnehmer und deren Altersberechnung
|
// Abrufen der Riegendaten einschließlich der Teilnehmer und deren Altersberechnung
|
||||||
const result = await pool.query(`
|
const result = await pool.query(`
|
||||||
SELECT r.riegennummer, t.id, t.name, t.vorname, t.nachname, t.geburtsdatum, r.helfer
|
SELECT r.riegennummer, t.id, t.name, t.vorname, t.nachname, t.geburtsdatum, r.helfer
|
||||||
FROM riegen r
|
FROM riegen r
|
||||||
JOIN teilnehmende t ON r.fremdID_Teilnehmende = t.id
|
JOIN teilnehmende t ON r.fremdID_Teilnehmende = t.id
|
||||||
ORDER BY r.riegennummer, t.geburtsdatum ASC
|
ORDER BY r.riegennummer, t.geburtsdatum ASC
|
||||||
`);
|
`);
|
||||||
|
|
||||||
// Gruppieren der Riegenteilnehmer nach Riegennummer
|
// Gruppieren der Riegenteilnehmer nach Riegennummer
|
||||||
const riegen = {};
|
const riegen = {};
|
||||||
result.rows.forEach(row => {
|
result.rows.forEach(row => {
|
||||||
const age = calculateAge(row.geburtsdatum);
|
const age = calculateAge(row.geburtsdatum);
|
||||||
const tnAnwesend = getAnwesenheit(row.id, anwesend);
|
const tnAnwesend = getAnwesenheit(row.id, anwesend);
|
||||||
if (!riegen[row.riegennummer]) {
|
if (!riegen[row.riegennummer]) {
|
||||||
riegen[row.riegennummer] = [];
|
riegen[row.riegennummer] = [];
|
||||||
}
|
}
|
||||||
riegen[row.riegennummer].push({
|
riegen[row.riegennummer].push({
|
||||||
id: row.id,
|
id: row.id,
|
||||||
name: row.name,
|
name: row.name,
|
||||||
vorname: row.vorname,
|
vorname: row.vorname,
|
||||||
nachname: row.nachname,
|
nachname: row.nachname,
|
||||||
age: age,
|
age: age,
|
||||||
helfer: row.helfer,
|
helfer: row.helfer,
|
||||||
anwesend: tnAnwesend
|
anwesend: tnAnwesend
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
});
|
||||||
|
|
||||||
if (training) {
|
if (training) {
|
||||||
training.datum = formatDate(training.datum);
|
training.datum = formatDate(training.datum);
|
||||||
|
@ -593,18 +595,18 @@ app.get('/training', requireAuth, async (req, res) => {
|
||||||
spielleiterCandidates,
|
spielleiterCandidates,
|
||||||
aufwaermenCandidates, // Übergeben der Kandidaten für Aufwärmleiter
|
aufwaermenCandidates, // Übergeben der Kandidaten für Aufwärmleiter
|
||||||
spielCandidates, // Übergeben der Spiele
|
spielCandidates, // Übergeben der Spiele
|
||||||
session: req.session,
|
session: req.session,
|
||||||
previousTraining,
|
previousTraining,
|
||||||
nextTraining,
|
nextTraining,
|
||||||
riegen,
|
riegen,
|
||||||
activeRiege: req.session.activeRiege,
|
activeRiege: req.session.activeRiege,
|
||||||
activeTab: req.session.activeTab,
|
activeTab: req.session.activeTab,
|
||||||
moment
|
moment
|
||||||
});
|
});
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(error);
|
console.error(error);
|
||||||
const message = 'Error:' + error;
|
const message = 'Error:' + error;
|
||||||
res.render('error', {session: req.session, message});
|
res.render('error', { session: req.session, message });
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -638,8 +640,8 @@ app.get('/riege', requireAuth, async (req, res) => {
|
||||||
res.render('riegen', { riegen: riegen, session: req.session });
|
res.render('riegen', { riegen: riegen, session: req.session });
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Error fetching riegen:', error);
|
console.error('Error fetching riegen:', error);
|
||||||
req.session.message = ['Error', error , 'error'];
|
req.session.message = ['Error', error, 'error'];
|
||||||
res.render('error', {session: req.session});
|
res.render('error', { session: req.session });
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -655,7 +657,7 @@ app.get('/teilnehmer', requireAuth, async (req, res) => {
|
||||||
res.render('teilnehmer', { teilnehmende, session: req.session });
|
res.render('teilnehmer', { teilnehmende, session: req.session });
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(error);
|
console.error(error);
|
||||||
req.session.message = ['Error', error , 'error'];
|
req.session.message = ['Error', error, 'error'];
|
||||||
res.render('error', { session: req.session });
|
res.render('error', { session: req.session });
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -676,21 +678,21 @@ app.get('/mitglied/:id', requireAuth, async (req, res) => {
|
||||||
...t,
|
...t,
|
||||||
age: calculateAge(t.geburtsdatum)
|
age: calculateAge(t.geburtsdatum)
|
||||||
}))
|
}))
|
||||||
res.render('mitglied', {
|
res.render('mitglied', {
|
||||||
id,
|
id,
|
||||||
mitglied: mitglied[0],
|
mitglied: mitglied[0],
|
||||||
numbers,
|
numbers,
|
||||||
riege,
|
riege,
|
||||||
anwesend,
|
anwesend,
|
||||||
session: req.session
|
session: req.session
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
req.session.message = ['Error', 'Mitglied existiert nicht' , 'error'];
|
req.session.message = ['Error', 'Mitglied existiert nicht', 'error'];
|
||||||
res.redirect('/teilnehmer')
|
res.redirect('/teilnehmer')
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Error in Mitglied:', error);
|
console.error('Error in Mitglied:', error);
|
||||||
req.session.message = ['Error', 'Mitglied existiert nicht' , 'error'];
|
req.session.message = ['Error', 'Mitglied existiert nicht', 'error'];
|
||||||
res.redirect('/teilnehmer');
|
res.redirect('/teilnehmer');
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -702,35 +704,35 @@ 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, telid, adresse, name, verbindung, nummer } = req.body;
|
const { type, id, telid, adresse, name, verbindung, nummer } = 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()]);
|
||||||
await pool.query('INSERT INTO telefonnummern (fid_teilnehmer, name, verbindung, nummer, stand) VALUES ($1, $2, $3, $4, $5)', [id, name, verbindung, nummer, moment().toDate()]);
|
await pool.query('INSERT INTO telefonnummern (fid_teilnehmer, name, verbindung, nummer, stand) VALUES ($1, $2, $3, $4, $5)', [id, name, verbindung, nummer, moment().toDate()]);
|
||||||
} else if (type=="tel-delete"){
|
} else if (type == "tel-delete") {
|
||||||
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 adresse = $1 WHERE id = $2', [adresse, id]);
|
await pool.query('UPDATE teilnehmende SET adresse = $1 WHERE id = $2', [adresse, id]);
|
||||||
}
|
}
|
||||||
|
|
||||||
res.redirect('/mitglied/' + id);
|
res.redirect('/mitglied/' + id);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(error);
|
console.error(error);
|
||||||
req.session.message = ['Error', error , 'error'];
|
req.session.message = ['Error', error, 'error'];
|
||||||
res.redirect('/mitglied/' + id);
|
res.redirect('/mitglied/' + id);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// Login und Registrierung anzeigen
|
// Login und Registrierung anzeigen
|
||||||
app.get('/login', (req, res) => {
|
app.get('/login', (req, res) => {
|
||||||
req.session.message=['', '', 'none'];
|
req.session.message = ['', '', 'none'];
|
||||||
res.render('login', {session: req.session}); // Stelle sicher, dass es eine login.ejs gibt
|
res.render('login', { session: req.session }); // Stelle sicher, dass es eine login.ejs gibt
|
||||||
});
|
});
|
||||||
|
|
||||||
// Registrierung
|
// Registrierung
|
||||||
app.get('/register', (req, res) => {
|
app.get('/register', (req, res) => {
|
||||||
res.render('register', {session: req.session}); // Stelle sicher, dass es eine register.ejs gibt
|
res.render('register', { session: req.session }); // Stelle sicher, dass es eine register.ejs gibt
|
||||||
});
|
});
|
||||||
|
|
||||||
// Spieleliste
|
// Spieleliste
|
||||||
|
@ -741,12 +743,12 @@ app.get('/spiele', async (req, res) => {
|
||||||
res.render('spiele', { spiele, session: req.session });
|
res.render('spiele', { spiele, session: req.session });
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Error in Mitglied:', error);
|
console.error('Error in Mitglied:', error);
|
||||||
req.session.message = ['Error', error , 'error'];
|
req.session.message = ['Error', error, 'error'];
|
||||||
res.render('spiele', { spiele, session: req.session });
|
res.render('spiele', { spiele, session: req.session });
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
app.post('/delete-spiel', requireAdmin ,async (req, res) => {
|
app.post('/delete-spiel', requireAdmin, async (req, res) => {
|
||||||
const { spielId } = req.body;
|
const { spielId } = req.body;
|
||||||
console.log(spielId);
|
console.log(spielId);
|
||||||
await pool.query('DELETE FROM spiele WHERE id = $1', [spielId]);
|
await pool.query('DELETE FROM spiele WHERE id = $1', [spielId]);
|
||||||
|
@ -759,38 +761,38 @@ app.get('/spiel/:id', async (req, res) => {
|
||||||
try {
|
try {
|
||||||
const spieleResult = await pool.query('SELECT * FROM spiele WHERE id = $1', [id]);
|
const spieleResult = await pool.query('SELECT * FROM spiele WHERE id = $1', [id]);
|
||||||
if (spieleResult.rows.length > 0) {
|
if (spieleResult.rows.length > 0) {
|
||||||
const spiel = spieleResult.rows[0];
|
const spiel = spieleResult.rows[0];
|
||||||
res.render('spiel', { spiel, session: req.session });
|
res.render('spiel', { spiel, session: req.session });
|
||||||
} else {
|
} else {
|
||||||
req.session.message = ['Error', 'Spiel existiert nicht', 'error'];
|
req.session.message = ['Error', 'Spiel existiert nicht', 'error'];
|
||||||
res.redirect('/spiele');
|
res.redirect('/spiele');
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Error in Spiele:', error);
|
console.error('Error in Spiele:', error);
|
||||||
req.session.message = ['Error', 'Spiel existiert nicht' , 'error'];
|
req.session.message = ['Error', 'Spiel existiert nicht', 'error'];
|
||||||
res.redirect('/spiele');
|
res.redirect('/spiele');
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
// Postseite für Änderungen
|
// Postseite für Änderungen
|
||||||
app.post('/edit-spiel', requireAuth, async (req, res) => {
|
app.post('/edit-spiel', requireAuth, async (req, res) => {
|
||||||
const { material, dauer, regeln, variationen, type, id } = req.body;
|
const { material, dauer, regeln, variationen, type, id } = req.body;
|
||||||
try {
|
try {
|
||||||
const queryResult = await pool.query('UPDATE spiele set material = $1, regeln = $2, dauer = $3, variationen = $4, type = $5 Where id = $6 ', [material, regeln, dauer, variationen, type, id]);
|
const queryResult = await pool.query('UPDATE spiele set material = $1, regeln = $2, dauer = $3, variationen = $4, type = $5 Where id = $6 ', [material, regeln, dauer, variationen, type, id]);
|
||||||
req.session.message = ['Erfolg', 'Das Spiel wurde gespeichert', 'success'];
|
req.session.message = ['Erfolg', 'Das Spiel wurde gespeichert', 'success'];
|
||||||
res.redirect('/spiel/' + id);
|
res.redirect('/spiel/' + id);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Error in edit Spiel:', error);
|
console.error('Error in edit Spiel:', error);
|
||||||
req.session.message = ['Error', error , 'error'];
|
req.session.message = ['Error', error, 'error'];
|
||||||
res.redirect('/spiel/' + id);
|
res.redirect('/spiel/' + id);
|
||||||
}
|
}
|
||||||
|
|
||||||
})
|
})
|
||||||
|
|
||||||
// Startseite
|
// Startseite
|
||||||
app.get('/', (req, res) => {
|
app.get('/', (req, res) => {
|
||||||
req.session.message = ['', '', 'none']
|
req.session.message = ['', '', 'none']
|
||||||
res.render('index', {session: req.session});
|
res.render('index', { session: req.session });
|
||||||
});
|
});
|
||||||
|
|
||||||
// Changelog
|
// Changelog
|
||||||
|
@ -798,11 +800,11 @@ app.get('/changelog', async (req, res) => {
|
||||||
try {
|
try {
|
||||||
const changeResult = await pool.query('SELECT * FROM changelog ORDER BY datetime DESC;');
|
const changeResult = await pool.query('SELECT * FROM changelog ORDER BY datetime DESC;');
|
||||||
const changes = changeResult.rows;
|
const changes = changeResult.rows;
|
||||||
req.session.message = ['Erfolg', 'Log gespeichert' , 'success'];
|
req.session.message = ['Erfolg', 'Log gespeichert', 'success'];
|
||||||
res.render('changelog', { changes, session: req.session });
|
res.render('changelog', { changes, session: req.session });
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Error:', error);
|
console.error('Error:', error);
|
||||||
req.session.message = ['Error', error , 'error'];
|
req.session.message = ['Error', error, 'error'];
|
||||||
res.redirect('/changelog');
|
res.redirect('/changelog');
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
@ -811,35 +813,37 @@ app.post('/changelog', requireAdmin, async (req, res) => {
|
||||||
const { title, body } = req.body;
|
const { title, body } = req.body;
|
||||||
try {
|
try {
|
||||||
await pool.query('INSERT INTO changelog (title, body) VALUES ($1, $2);', [title, body]);
|
await pool.query('INSERT INTO changelog (title, body) VALUES ($1, $2);', [title, body]);
|
||||||
|
|
||||||
const changeResult = await pool.query('SELECT * FROM changelog ORDER BY datetime DESC;');
|
const changeResult = await pool.query('SELECT * FROM changelog ORDER BY datetime DESC;');
|
||||||
const changes = changeResult.rows;
|
const changes = changeResult.rows;
|
||||||
res.render('changelog', { changes, session: req.session });
|
res.render('changelog', { changes, session: req.session });
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Error:', error);
|
console.error('Error:', error);
|
||||||
req.session.message = ['Error', error , 'error'];
|
req.session.message = ['Error', error, 'error'];
|
||||||
res.render('changelog', { changes, session: req.session });
|
res.render('changelog', { changes, session: req.session });
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
app.post('/anwesend', requireAuth, async (req, res) => {
|
app.post('/anwesend', requireAuth, async (req, res) => {
|
||||||
const { anw, trainingId, riege } = req.body;
|
const { anw, trainingId, riege } = req.body;
|
||||||
req.session.activeTab = 'anwesend';
|
req.session.activeTab = 'anwesend';
|
||||||
req.session.message = [title = 'Erfolg', body = 'Die Anwesenheit wurde gespeichert', type = 'success'];
|
req.session.message = [title = 'Erfolg', body = 'Die Anwesenheit wurde gespeichert', type = 'success'];
|
||||||
try {
|
try {
|
||||||
for (const teilnehmer of anw) {
|
for (const teilnehmer of anw) {
|
||||||
const resultAnw = await pool.query('Select * FROM anwesend WHERE fid_teilnehmer = $1 AND fid_training = $2', [teilnehmer, trainingId]);
|
const resultAnw = await pool.query('Select * FROM anwesend WHERE fid_teilnehmer = $1 AND fid_training = $2', [teilnehmer, trainingId]);
|
||||||
if (resultAnw.rows.length == 0) {
|
if (resultAnw.rows.length == 0) {
|
||||||
await pool.query('INSERT INTO anwesend (fid_teilnehmer, fid_training) VALUES ($1, $2)', [teilnehmer, trainingId]);
|
await pool.query('INSERT INTO anwesend (fid_teilnehmer, fid_training) VALUES ($1, $2)', [teilnehmer, trainingId]);
|
||||||
}}
|
}
|
||||||
req.session.activeRiege = riege;
|
}
|
||||||
res.redirect('/training');
|
req.session.activeRiege = riege;
|
||||||
} catch (error) {
|
res.redirect('/training');
|
||||||
console.error('Error:', error);
|
} catch (error) {
|
||||||
req.session.message = ['Error', error , 'error'];
|
console.error('Error:', error);
|
||||||
res.redirect('/training');
|
req.session.message = ['Error', error, 'error'];
|
||||||
}})
|
res.redirect('/training');
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
const server = app.listen(port, '0.0.0.0', () => {
|
const server = app.listen(port, '0.0.0.0', () => {
|
||||||
log.Info(`Server is running on ${process.env.HOST}:${port}/`);
|
log.Info(`Server is running on ${process.env.HOST}:${port}/`);
|
||||||
});
|
});
|
Loading…
Reference in New Issue