feat: team indeling endpoint + proposed_teams field

This commit is contained in:
root
2026-05-25 08:29:01 +00:00
parent 099908c303
commit 558544e461
2 changed files with 31 additions and 2 deletions
+23
View File
@@ -363,6 +363,29 @@ app.delete("/api/matches/:id", (req, res) => {
res.json({ ok: true });
});
// ─── TEAM INDELING (voorgesteld) ───
app.post("/api/matches/:id/teams", (req, res) => {
let m = db.getMatch(String(req.params.id));
if (!m) return res.status(404).json({ error: "match not found" });
const { team1, team2 } = req.body;
if (!Array.isArray(team1) || !Array.isArray(team2))
return res.status(400).json({ error: "team1 and team2 must be arrays" });
const allIds = [...team1, ...team2];
if (allIds.length !== 4)
return res.status(400).json({ error: "expected 4 players total" });
db.updateMatch(String(req.params.id), { proposed_teams: { team1, team2 } });
m = db.getMatch(String(req.params.id));
const playerIds = (m.players || []).map(p => p.id);
res.json({ ...m, players: playerIds, players_array: m.players });
});
app.get("/api/matches/:id/teams", (req, res) => {
const m = db.getMatch(String(req.params.id));
if (!m) return res.status(404).json({ error: "match not found" });
const teams = m.proposed_teams || null;
res.json({ teams, match: { id: m.id, date: m.date, start: m.start, status: m.status } });
});
// ─── SCORES ───
app.post("/api/matches/:id/score", (req, res) => {
let m = db.getMatch(String(req.params.id));