commit
8a54feeea4
37
app.js
37
app.js
|
@ -597,7 +597,17 @@ app.get("/admin", requireAuth, requireAdmin, async (req, res) => {
|
|||
});
|
||||
|
||||
app.post("/new-member", requireAuth, requireAdmin, async (req, res) => {
|
||||
const { vorname, nachname, geburt, riege, adresse, probe } = req.body;
|
||||
var {
|
||||
from,
|
||||
vorname,
|
||||
nachname,
|
||||
geburt,
|
||||
riege,
|
||||
adresse,
|
||||
probe,
|
||||
from,
|
||||
training,
|
||||
} = req.body;
|
||||
var geb = "01.01.2024";
|
||||
const name = vorname + " " + nachname;
|
||||
try {
|
||||
|
@ -608,11 +618,24 @@ 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]
|
||||
);
|
||||
|
||||
log.Info(
|
||||
"Mitglied " + name + " durch " + req.session.userName + " angelegt"
|
||||
);
|
||||
putInRiege(riege, teilnehmerID.rows[0].id);
|
||||
res.redirect("/riege");
|
||||
req.session.activeRiege = riege;
|
||||
req.session.activeTab = "anwesend";
|
||||
res.redirect("/training");
|
||||
} catch (error) {
|
||||
const message = "Error:" + error;
|
||||
res.render("error", { session: req.session, message });
|
||||
|
@ -1070,6 +1093,16 @@ app.post("/anwesend", requireAuth, async (req, res) => {
|
|||
}
|
||||
});
|
||||
|
||||
app.post("/deleteMember", requireAuth, async (req, res) => {
|
||||
const { id } = req.body;
|
||||
try {
|
||||
await pool.query("DELETE from teilnehmende WHERE id = $1", [id]);
|
||||
} catch (error) {
|
||||
console.error("Error:", error);
|
||||
}
|
||||
res.redirect("/teilnehmer");
|
||||
});
|
||||
|
||||
const server = app.listen(port, "0.0.0.0", () => {
|
||||
log.Info(`Server is running on ${process.env.HOST}:${port}/`);
|
||||
});
|
||||
|
|
|
@ -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>
|
||||
|
||||
|
|
|
@ -97,7 +97,8 @@
|
|||
</p>
|
||||
</fieldset>
|
||||
|
||||
<h2>Telefonnummer hinzufügen</h2>
|
||||
<fieldset>
|
||||
<legend>Telefonnummern hinzufügen</legend>
|
||||
<form method="POST" action="/update-mitglied">
|
||||
<input type="hidden" name="id" value="<%= id %>">
|
||||
<input type="hidden" name="type" value="tel">
|
||||
|
@ -113,6 +114,38 @@
|
|||
<input name="nummer" placeholder="+49 123 456 789" type="text">
|
||||
<button type="submit">Speichern</button>
|
||||
</form>
|
||||
</fieldset>
|
||||
<p>
|
||||
<!-- Button trigger modal -->
|
||||
<button type="button" class="btn btn-danger" data-bs-toggle="modal" data-bs-target="#deleteModal">
|
||||
Mitglied löschen
|
||||
</button></br>
|
||||
</p>
|
||||
<!-- Modal -->
|
||||
<div class="modal fade" id="deleteModal" tabindex="-1" aria-labelledby="deleteModalLabel" aria-hidden="true">
|
||||
<div class="modal-dialog">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<h1 class="modal-title fs-5" id="exampleModalLabel">Mitglied löschen</h1>
|
||||
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<p>Möchtest du das Mitglied <%= mitglied.vorname %> <%= mitglied.nachname %> wirklich löschen?
|
||||
Diese Aktion kann nicht rüchgängig gemacht werden!
|
||||
</p>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
|
||||
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button>
|
||||
<form method="POST" action="/deleteMember">
|
||||
<input type="hidden" name="id" value="<%= id %>">
|
||||
<button type="submit" class="btn btn-danger">Löschen</button>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<button class="btn btn-secondary" onclick="toggleDivs()">Zum View-Modus wechseln</button>
|
||||
</div>
|
||||
<% } %>
|
||||
|
|
|
@ -328,6 +328,49 @@
|
|||
<button type="submit">Speichern</button>
|
||||
<% } %>
|
||||
</form>
|
||||
|
||||
<button type="button" class="btn btn-primary" data-bs-toggle="modal" data-bs-target="#newMemberModal-<%= riegennummer %>">
|
||||
Neues Mitglied
|
||||
</button>
|
||||
|
||||
<!-- Modal -->
|
||||
<div class="modal fade" id="newMemberModal-<%= riegennummer %>" tabindex="-1" aria-labelledby="newMemberModalLabel" aria-hidden="true">
|
||||
<div class="modal-dialog">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<h1 class="modal-title fs-5" id="exampleModalLabel">Neues Mitglied</h1>
|
||||
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<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>
|
||||
Geburtsdatum: <input type="date" id="geburt" name="geburt"></br>
|
||||
<select name="riege" value="<%= riegennummer %>">
|
||||
<option value=1 <%= riegennummer == 1 ? 'selected' : '' %>> Riege 1</option>
|
||||
<option value=2 <%= riegennummer == 2 ? 'selected' : '' %>> Riege 2</option>
|
||||
<option value=3 <%= riegennummer == 3 ? 'selected' : '' %>> Riege 3</option>
|
||||
<option value=4 <%= riegennummer == 4 ? 'selected' : '' %>> Riege 4</option>
|
||||
<option value=5 <%= riegennummer == 5 ? 'selected' : '' %>> 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>
|
||||
<input type="hidden" name="from" value="training">
|
||||
<input type="hidden" name="training" value="<%= training.id %>">
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button type="submit">Speichern</button>
|
||||
</form>
|
||||
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
</div>
|
||||
<% }) %>
|
||||
</div>
|
||||
|
|
Loading…
Reference in New Issue