feat(backend): implement phases 0-6 (auth, kc, wahl, files, chat, sync)

Full NestJS backend for the KC-App platform:
- auth: Authentik OIDC resource-server strategy + guest invite-code JWT
  login, plus TokenVerificationService for the WS handshake path
- kc: Leitungsteam-only KC (event) creation/listing
- wahl: Wahl/Workshop admin, Force-Zuteilung overrides, ZuteilungService
  (port of the WP plugin's kc_run_zuteilung), CSV export
- files: LT-only upload with visibility tiers; list/download filtered by
  caller tier; StorageProvider abstraction (WebDAV/Nextcloud default, S3)
- chat: Gemeinde group / DM / LT-wide / broadcast channels; REST + raw ws
  gateway sharing ChatService access rules
- sync: append-only SyncLogEntry replication log + local<->cloud
  push/pull scheduler, shared-secret guarded
- common: Role enum, @Roles decorator, KC-scoped RolesGuard (LT global)
- serves client/web/ interim static web client under / (API under /api)

Typecheck, nest build and boot test pass; needs real Postgres/Authentik/
Nextcloud to run end to end.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
2026-09-09 16:23:45 +02:00
co-authored by Claude Sonnet 5
parent e49eed871c
commit 7aba87368d
47 changed files with 3003 additions and 115 deletions
+92
View File
@@ -0,0 +1,92 @@
const state = { token: null, kcId: null, socket: null };
const $ = (id) => document.getElementById(id);
function decodeJwtPayload(token) {
try {
const [, payload] = token.split('.');
return JSON.parse(atob(payload.replace(/-/g, '+').replace(/_/g, '/')));
} catch {
return null;
}
}
$('guest-form').addEventListener('submit', async (event) => {
event.preventDefault();
const inviteCode = $('invite-code').value;
const firstName = $('first-name').value;
const lastName = $('last-name').value;
const res = await fetch('/api/auth/guest', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ inviteCode, firstName, lastName }),
});
if (!res.ok) {
$('login-status').textContent = `Fehler: ${res.status}`;
return;
}
const { accessToken } = await res.json();
state.token = accessToken;
state.kcId = decodeJwtPayload(accessToken)?.kcId ?? null;
$('login-status').textContent = 'Angemeldet.';
$('login-section').hidden = true;
$('app-section').hidden = false;
});
$('submit-wahl').addEventListener('click', async () => {
const wahlId = $('wahl-id').value;
const prioritaeten = $('prioritaeten')
.value.split(',')
.map((s) => s.trim())
.filter(Boolean);
const res = await fetch(`/api/wahl/${wahlId}/teilnehmer`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
Authorization: `Bearer ${state.token}`,
},
body: JSON.stringify({ prioritaeten }),
});
$('wahl-status').textContent = res.ok ? 'Gespeichert.' : `Fehler: ${res.status}`;
});
$('load-files').addEventListener('click', async () => {
if (!state.kcId) return;
const res = await fetch(`/api/files/${state.kcId}`, {
headers: { Authorization: `Bearer ${state.token}` },
});
const files = res.ok ? await res.json() : [];
const list = $('file-list');
list.innerHTML = '';
for (const file of files) {
const li = document.createElement('li');
li.textContent = file.filename;
list.appendChild(li);
}
});
$('join-channel').addEventListener('click', () => {
const channelId = $('channel-id').value;
if (!channelId || !state.token) return;
if (state.socket) state.socket.close();
const protocol = location.protocol === 'https:' ? 'wss' : 'ws';
const socket = new WebSocket(`${protocol}://${location.host}/chat?token=${state.token}`);
state.socket = socket;
socket.addEventListener('open', () => {
socket.send(JSON.stringify({ event: 'chat:join', data: { channelId } }));
});
socket.addEventListener('message', (event) => {
const { event: name, data } = JSON.parse(event.data);
if (name !== 'chat:message') return;
const li = document.createElement('li');
li.textContent = data.body;
$('chat-log').appendChild(li);
});
});
+51
View File
@@ -0,0 +1,51 @@
<!DOCTYPE html>
<html lang="de">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>KC-App</title>
<link rel="stylesheet" href="style.css" />
</head>
<body>
<header>
<h1>KC-App</h1>
<p class="subtitle">Web-Client (Platzhalter, bis der Flutter-Client bereitsteht)</p>
</header>
<main>
<section id="login-section">
<h2>Guest/Konfi-Zugang</h2>
<form id="guest-form">
<label>Einladungscode <input id="invite-code" name="inviteCode" required /></label>
<label>Vorname <input id="first-name" name="firstName" required /></label>
<label>Nachname <input id="last-name" name="lastName" required /></label>
<button type="submit">Beitreten</button>
</form>
<p id="login-status"></p>
</section>
<section id="app-section" hidden>
<h2>Wahl</h2>
<div>
<label>Wahl-ID <input id="wahl-id" /></label>
<label>Priorit&auml;ten (Workshop-IDs, Komma-getrennt) <input id="prioritaeten" /></label>
<button id="submit-wahl">Absenden</button>
</div>
<p id="wahl-status"></p>
<h2>Dateien</h2>
<button id="load-files">Dateien laden</button>
<ul id="file-list"></ul>
<h2>Chat (Broadcast)</h2>
<div>
<label>Channel-ID <input id="channel-id" /></label>
<button id="join-channel">Beitreten</button>
</div>
<ul id="chat-log"></ul>
</section>
</main>
<script src="app.js"></script>
</body>
</html>
+62
View File
@@ -0,0 +1,62 @@
body {
font-family: system-ui, sans-serif;
max-width: 640px;
margin: 2rem auto;
padding: 0 1rem;
color: #1a1a1a;
}
header {
margin-bottom: 2rem;
}
.subtitle {
color: #666;
font-size: 0.9rem;
}
section {
margin-bottom: 2rem;
}
form,
#app-section > div {
display: flex;
flex-direction: column;
gap: 0.5rem;
max-width: 360px;
margin-bottom: 1rem;
}
label {
display: flex;
flex-direction: column;
font-size: 0.9rem;
gap: 0.25rem;
}
input {
padding: 0.4rem;
font-size: 1rem;
}
button {
padding: 0.5rem;
cursor: pointer;
}
#chat-log,
#file-list {
list-style: none;
padding: 0;
border: 1px solid #ddd;
border-radius: 4px;
max-height: 200px;
overflow-y: auto;
}
#chat-log li,
#file-list li {
padding: 0.4rem 0.6rem;
border-bottom: 1px solid #eee;
}