feat: match_type (ranked/friendly) + /api/matches/:id/type endpoint

This commit is contained in:
root
2026-05-25 09:27:31 +00:00
parent 558544e461
commit d192a02cc5
2 changed files with 23 additions and 5 deletions
+14 -1
View File
@@ -383,7 +383,20 @@ 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 } });
res.json({ teams, match: { id: m.id, date: m.date, start: m.start, status: m.status, match_type: m.match_type || 'friendly' } });
});
// ─── MATCH TYPE (ranked/friendly) ───
app.post("/api/matches/:id/type", (req, res) => {
let m = db.getMatch(String(req.params.id));
if (!m) return res.status(404).json({ error: "match not found" });
const { match_type } = req.body;
if (match_type !== 'ranked' && match_type !== 'friendly')
return res.status(400).json({ error: "match_type must be 'ranked' or 'friendly'" });
db.updateMatch(String(req.params.id), { match_type });
m = db.getMatch(String(req.params.id));
const playerIds = (m.players || []).map(p => p.id);
res.json({ ...m, players: playerIds, players_array: m.players });
});
// ─── SCORES ───