Korrektur bei Mitglied anlegen auf Admin seite
This commit is contained in:
parent
52f36328d5
commit
95b322e4a6
41
app.js
41
app.js
|
@ -597,8 +597,17 @@ 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 { from, vorname, nachname, geburt, riege, adresse, probe, training } =
|
var {
|
||||||
req.body;
|
from,
|
||||||
|
vorname,
|
||||||
|
nachname,
|
||||||
|
geburt,
|
||||||
|
riege,
|
||||||
|
adresse,
|
||||||
|
probe,
|
||||||
|
from,
|
||||||
|
training,
|
||||||
|
} = req.body;
|
||||||
var geb = "01.01.2024";
|
var geb = "01.01.2024";
|
||||||
const name = vorname + " " + nachname;
|
const name = vorname + " " + nachname;
|
||||||
try {
|
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",
|
"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]
|
[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(
|
await pool.query(
|
||||||
"INSERT INTO anwesend (fid_teilnehmer, fid_training) VALUES ($1, $2)",
|
"INSERT INTO anwesend (fid_teilnehmer, fid_training) VALUES ($1, $2)",
|
||||||
[teilnehmerID.rows[0].id, training]
|
[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"
|
"Mitglied " + name + " durch " + req.session.userName + " angelegt"
|
||||||
);
|
);
|
||||||
putInRiege(riege, teilnehmerID.rows[0].id);
|
putInRiege(riege, teilnehmerID.rows[0].id);
|
||||||
if (from === "admin") {
|
req.session.activeRiege = riege;
|
||||||
res.redirect("/riege");
|
req.session.activeTab = "anwesend";
|
||||||
} else if (from === "training") {
|
res.redirect("/training");
|
||||||
req.session.activeRiege = riege;
|
|
||||||
req.session.activeTab = "anwesend";
|
|
||||||
res.redirect("/training");
|
|
||||||
}
|
|
||||||
} 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 });
|
||||||
|
@ -1082,15 +1093,15 @@ app.post("/anwesend", requireAuth, async (req, res) => {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
app.post('/deleteMember', requireAuth, async (req, res) => {
|
app.post("/deleteMember", requireAuth, async (req, res) => {
|
||||||
const { id } = req.body
|
const { id } = req.body;
|
||||||
try {
|
try {
|
||||||
await pool.query('DELETE from teilnehmende WHERE id = $1', [id])
|
await pool.query("DELETE from teilnehmende WHERE id = $1", [id]);
|
||||||
} catch (error) {
|
} 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", () => {
|
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}/`);
|
||||||
|
|
|
@ -28,6 +28,8 @@
|
||||||
</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>
|
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>
|
<button type="submit">Speichern</button>
|
||||||
</form>
|
</form>
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue