feat: implement table assignment and distribution for tournament matches
All checks were successful
Deploy tt-tagebuch / deploy (push) Successful in 44s

This commit is contained in:
Torsten Schulz (local)
2026-05-17 23:55:39 +02:00
parent 6c7ae6860b
commit 697e67d46e
16 changed files with 426 additions and 22 deletions

View File

@@ -44,7 +44,7 @@ async function run() {
console.log('[api-test] Using token for tournament', targetTournament.id, 'club', targetTournament.clubId);
const url = `http://localhost:3005/tournament/${targetTournament.clubId}/${targetTournament.id}`;
const url = `http://localhost:3005/api/tournament/${targetTournament.clubId}/${targetTournament.id}`;
const payload = {
name: targetTournament.name || 'Test Tournament',
date: targetTournament.date,

View File

@@ -0,0 +1,29 @@
import '../config.js';
import sequelize from '../database.js';
import jwt from 'jsonwebtoken';
import User from '../models/User.js';
import UserToken from '../models/UserToken.js';
(async () => {
try {
await sequelize.authenticate();
console.log('[create-token] DB connected');
const email = process.env.TEST_TOKEN_EMAIL || 'tournamentmanager@test.de';
const user = await User.findOne({ where: { email } });
if (!user) {
console.error('[create-token] User not found:', email);
process.exit(2);
}
const payload = { userId: user.id };
const token = jwt.sign(payload, process.env.JWT_SECRET, { expiresIn: '7d' });
const expiresAt = new Date(Date.now() + 7 * 24 * 3600 * 1000);
await UserToken.create({ userId: user.id, token, expiresAt });
console.log('[create-token] TOKEN_START');
console.log(token);
console.log('[create-token] TOKEN_END');
process.exit(0);
} catch (err) {
console.error('[create-token] Error:', err);
process.exit(3);
}
})();

View File

@@ -0,0 +1,51 @@
import '../config.js';
import sequelize from '../database.js';
import TournamentMatch from '../models/TournamentMatch.js';
const argv = process.argv.slice(2);
if (argv.length === 0) {
console.error('Usage: node inspect_and_fix_active_matches.js <tournamentId> [--fix-all]');
process.exit(2);
}
const tournamentId = Number(argv[0]);
const fixAll = argv.includes('--fix-all') || argv.includes('--fix');
(async () => {
try {
await sequelize.authenticate();
console.log('[inspect] DB connected');
const active = await TournamentMatch.findAll({
where: { tournamentId, isActive: true },
order: [['id', 'ASC']]
});
console.log(`[inspect] active matches for tournament ${tournamentId}: ${active.length}`);
for (const m of active) {
console.log(` id=${m.id} p1=${m.player1Id} p2=${m.player2Id} isFinished=${m.isFinished} table=${m.tableNumber}`);
}
const candidates = await TournamentMatch.findAll({
where: { tournamentId, isFinished: false, tableNumber: null },
order: [['id', 'ASC']]
});
console.log(`[inspect] candidate matches (not finished, no table): ${candidates.length}`);
for (const m of candidates) {
console.log(` id=${m.id} p1=${m.player1Id} p2=${m.player2Id} isActive=${m.isActive}`);
}
if (fixAll) {
console.log('[inspect] Fix mode: resetting isActive=false for all matches in tournament');
const [upd] = await sequelize.query('UPDATE tournament_match SET is_active = 0 WHERE tournament_id = :t', { replacements: { t: tournamentId } });
console.log('[inspect] Raw update result:', upd);
const nowActive = await TournamentMatch.count({ where: { tournamentId, isActive: true } });
console.log('[inspect] Remaining active matches:', nowActive);
}
process.exit(0);
} catch (err) {
console.error('[inspect] Error:', err);
process.exit(3);
}
})();