feat: match_type (ranked/friendly) + /api/matches/:id/type endpoint
This commit is contained in:
@@ -75,6 +75,9 @@ function migrateSchema() {
|
||||
CREATE INDEX IF NOT EXISTS idx_matchp_match ON match_players(match_id);
|
||||
CREATE INDEX IF NOT EXISTS idx_matchp_player ON match_players(player_id);
|
||||
|
||||
-- Migration: match type kolom
|
||||
ALTER TABLE matches ADD COLUMN match_type TEXT NOT NULL DEFAULT 'friendly';
|
||||
|
||||
CREATE TABLE IF NOT EXISTS sessions (
|
||||
id TEXT PRIMARY KEY,
|
||||
player_id TEXT REFERENCES players(id) ON DELETE SET NULL,
|
||||
@@ -249,8 +252,8 @@ function addMatch(match) {
|
||||
const db = getDb();
|
||||
const id = match.id || String(Date.now());
|
||||
const stmt = db.prepare(`
|
||||
INSERT INTO matches (id, status, responses, proposed_at, date, start, end, location, day, score, booker_id, booker_name)
|
||||
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
||||
INSERT INTO matches (id, status, responses, proposed_at, date, start, end, location, day, score, booker_id, booker_name, match_type)
|
||||
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
||||
`);
|
||||
stmt.run(id, match.status || 'proposed',
|
||||
JSON.stringify(match.responses || {}),
|
||||
@@ -260,7 +263,8 @@ function addMatch(match) {
|
||||
match.day || null,
|
||||
typeof match.score === 'object' ? JSON.stringify(match.score) : (match.score || null),
|
||||
match.booker_id || null,
|
||||
match.booker_name || null);
|
||||
match.booker_name || null,
|
||||
match.match_type || 'friendly');
|
||||
|
||||
if (Array.isArray(match.players)) {
|
||||
const pstmt = db.prepare(`INSERT INTO match_players (match_id, player_id, team, score) VALUES (?, ?, ?, ?)`);
|
||||
@@ -286,7 +290,7 @@ function updateMatch(id, match) {
|
||||
// Build SET dynamically to only update provided fields
|
||||
const fields = [];
|
||||
const values = [];
|
||||
for (const key of ['status', 'responses', 'proposed_at', 'date', 'start', 'end', 'location', 'day', 'score', 'booker_id', 'booker_name', 'proposed_teams']) {
|
||||
for (const key of ['status', 'responses', 'proposed_at', 'date', 'start', 'end', 'location', 'day', 'score', 'booker_id', 'booker_name', 'proposed_teams', 'match_type']) {
|
||||
if (match[key] !== undefined) {
|
||||
fields.push(`${key}=?`);
|
||||
let val = merged[key];
|
||||
@@ -463,6 +467,7 @@ function rowToMatch(r) {
|
||||
day: r.day,
|
||||
score: score,
|
||||
proposed_teams: proposed_teams,
|
||||
match_type: r.match_type || 'friendly',
|
||||
booker_id: r.booker_id || null,
|
||||
booker_name: r.booker_name || null,
|
||||
players: players
|
||||
|
||||
Reference in New Issue
Block a user