Korrektur bei Mitglied anlegen auf Admin seite

This commit is contained in:
klaas 2024-09-28 13:56:45 +02:00
parent 52f36328d5
commit 95b322e4a6
2 changed files with 28 additions and 15 deletions

41
app.js
View File

@ -597,8 +597,17 @@ app.get("/admin", requireAuth, requireAdmin, async (req, res) => {
});
app.post("/new-member", requireAuth, requireAdmin, async (req, res) => {
const { from, vorname, nachname, geburt, riege, adresse, probe, training } =
req.body;
var {
from,
vorname,
nachname,
geburt,
riege,
adresse,
probe,
from,
training,
} = req.body;
var geb = "01.01.2024";
const name = vorname + " " + nachname;
try {
@ -609,6 +618,12 @@ app.post("/new-member", requireAuth, requireAdmin, async (req, res) => {
"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]
);
if (from === "admin") {
selectedKW = moment().isoWeek();
selectedYear = moment().year();
const trainingresult = await getTraining(selectedKW, selectedYear);
training = trainingresult.id;
}
await pool.query(
"INSERT INTO anwesend (fid_teilnehmer, fid_training) VALUES ($1, $2)",
[teilnehmerID.rows[0].id, training]
@ -618,13 +633,9 @@ app.post("/new-member", requireAuth, requireAdmin, async (req, res) => {
"Mitglied " + name + " durch " + req.session.userName + " angelegt"
);
putInRiege(riege, teilnehmerID.rows[0].id);
if (from === "admin") {
res.redirect("/riege");
} else if (from === "training") {
req.session.activeRiege = riege;
req.session.activeTab = "anwesend";
res.redirect("/training");
}
req.session.activeRiege = riege;
req.session.activeTab = "anwesend";
res.redirect("/training");
} catch (error) {
const message = "Error:" + error;
res.render("error", { session: req.session, message });
@ -1082,15 +1093,15 @@ app.post("/anwesend", requireAuth, async (req, res) => {
}
});
app.post('/deleteMember', requireAuth, async (req, res) => {
const { id } = req.body
app.post("/deleteMember", requireAuth, async (req, res) => {
const { id } = req.body;
try {
await pool.query('DELETE from teilnehmende WHERE id = $1', [id])
await pool.query("DELETE from teilnehmende WHERE id = $1", [id]);
} catch (error) {
console.error('Error:', error)
console.error("Error:", error);
}
res.redirect('/training')
})
res.redirect("/teilnehmer");
});
const server = app.listen(port, "0.0.0.0", () => {
log.Info(`Server is running on ${process.env.HOST}:${port}/`);

View File

@ -28,6 +28,8 @@
</select></br>
Adresse: <input type="text" id="adresse" placeholder="Adresse" name="adresse"></br>
Probe: <input type="checkbox" name="probe" value="true"></br>
<input type="hidden" name="from" value="admin">
<input type="hidden" name="training" value="0">
<button type="submit">Speichern</button>
</form>