prob fix credits

This commit is contained in:
Jeremy Kirsch 2026-05-18 19:49:13 +02:00
parent 95fc830017
commit 05d9bbdc86
3 changed files with 1111 additions and 2869 deletions

File diff suppressed because it is too large Load Diff

View File

@ -1,6 +1,6 @@
const express = require('express');
const router = express.Router();
const db = require('../db');
const router = express.Router();
const db = require('../db');
const { requireAdmin } = require('../middleware/auth');
// Alle Admin-Routen erfordern Admin-Zugriff
@ -10,11 +10,11 @@ router.use(requireAdmin);
router.get('/stats', async (req, res) => {
try {
const [[{ ghosts }]] = await db.execute('SELECT COUNT(*) as ghosts FROM ghosts');
const [[{ total }]] = await db.execute('SELECT COUNT(*) as total FROM submissions');
const [[{ ghosts }]] = await db.execute('SELECT COUNT(*) as ghosts FROM ghosts');
const [[{ total }]] = await db.execute('SELECT COUNT(*) as total FROM submissions');
const [[{ pending }]] = await db.execute("SELECT COUNT(*) as pending FROM submissions WHERE status='pending'");
const [[{ approved }]] = await db.execute("SELECT COUNT(*) as approved FROM submissions WHERE status='approved'");
const [[{ rejected }]] = await db.execute("SELECT COUNT(*) as rejected FROM submissions WHERE status='rejected'");
const [[{ approved }]]= await db.execute("SELECT COUNT(*) as approved FROM submissions WHERE status='approved'");
const [[{ rejected }]]= await db.execute("SELECT COUNT(*) as rejected FROM submissions WHERE status='rejected'");
res.json({ ghosts, total, pending, approved, rejected });
} catch (e) {
res.status(500).json({ error: 'DB-Fehler' });
@ -33,9 +33,9 @@ router.post('/ghosts', async (req, res) => {
await db.query(
`INSERT INTO ghosts (id, name, evidence, sanity, hunt, sanity_special, tip, description, tells, updated_by)
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`,
[id, name, JSON.stringify(evidence), sanity || 50, hunt || 'mid',
sanity_special || '', tip || '', description || '', JSON.stringify(tells || []),
req.user.username]
[id, name, JSON.stringify(evidence), sanity||50, hunt||'mid',
sanity_special||'', tip||'', description||'', JSON.stringify(tells||[]),
req.user.username]
);
res.json({ ok: true });
} catch (e) {
@ -55,9 +55,9 @@ router.put('/ghosts/:id', async (req, res) => {
const result = await db.query(
`UPDATE ghosts SET name=?, evidence=?, sanity=?, hunt=?, sanity_special=?,
tip=?, description=?, tells=?, updated_by=? WHERE id=?`,
[name, JSON.stringify(evidence), sanity || 50, hunt || 'mid',
sanity_special || '', tip || '', description || '', JSON.stringify(tells || []),
req.user.username, req.params.id]
[name, JSON.stringify(evidence), sanity||50, hunt||'mid',
sanity_special||'', tip||'', description||'', JSON.stringify(tells||[]),
req.user.username, req.params.id]
);
if (result.affectedRows === 0) return res.status(404).json({ error: 'Geist nicht gefunden' });
res.json({ ok: true });
@ -96,11 +96,11 @@ router.get('/submissions', async (req, res) => {
// Submission reviewen (approve/reject)
router.patch('/submissions/:id', async (req, res) => {
const { status, admin_note } = req.body;
if (!['approved', 'rejected'].includes(status)) return res.status(400).json({ error: 'Status muss approved oder rejected sein' });
if (!['approved','rejected'].includes(status)) return res.status(400).json({ error: 'Status muss approved oder rejected sein' });
try {
await db.query(
`UPDATE submissions SET status=?, admin_note=?, reviewed_at=NOW(), reviewed_by=? WHERE id=?`,
[status, admin_note || '', req.user.username, req.params.id]
[status, admin_note||'', req.user.username, req.params.id]
);
res.json({ ok: true });
} catch (e) {
@ -127,7 +127,7 @@ router.post('/whitelist', async (req, res) => {
try {
await db.query(
'INSERT INTO admin_whitelist (discord_id, discord_username, added_by) VALUES (?,?,?)',
[discord_id.trim(), discord_username || discord_id, req.user.username]
[discord_id.trim(), discord_username||discord_id, req.user.username]
);
res.json({ ok: true });
} catch (e) {
@ -161,8 +161,8 @@ router.post('/credits', async (req, res) => {
await db.query(
`INSERT INTO credits (id, name, type, role, avatar, emoji, description, discord, website, roblox, sort_order)
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`,
[id, name, type || 'credit', role || '', avatar || '', emoji || '👤',
description || '', discord || '', website || '', roblox || '', sort_order || 0]
[id, name, type||'credit', role||'', avatar||'', emoji||'👤',
description||'', discord||'', website||'', roblox||'', sort_order||0]
);
res.json({ ok: true });
} catch (e) {
@ -180,8 +180,8 @@ router.put('/credits/:id', async (req, res) => {
const result = await db.query(
`UPDATE credits SET name=?, type=?, role=?, avatar=?, emoji=?, description=?,
discord=?, website=?, roblox=?, sort_order=? WHERE id=?`,
[name, type || 'credit', role || '', avatar || '', emoji || '👤',
description || '', discord || '', website || '', roblox || '', sort_order || 0, req.params.id]
[name, type||'credit', role||'', avatar||'', emoji||'👤',
description||'', discord||'', website||'', roblox||'', sort_order||0, req.params.id]
);
if (result.affectedRows === 0) return res.status(404).json({ error: 'Nicht gefunden' });
res.json({ ok: true });

View File

@ -1,6 +1,6 @@
const express = require('express');
const router = express.Router();
const db = require('../db');
const router = express.Router();
const db = require('../db');
const { requireAuth } = require('../middleware/auth');
// ── Ghosts (public read) ──────────────────────────────
@ -12,7 +12,7 @@ router.get('/ghosts', async (req, res) => {
const ghosts = rows.map(row => ({
...row,
evidence: typeof row.evidence === 'string' ? JSON.parse(row.evidence) : row.evidence,
tells: typeof row.tells === 'string' ? JSON.parse(row.tells) : row.tells,
tells: typeof row.tells === 'string' ? JSON.parse(row.tells) : row.tells,
}));
res.json(ghosts);
} catch (e) {
@ -40,7 +40,7 @@ router.get('/submissions/mine', requireAuth, async (req, res) => {
router.post('/submissions', requireAuth, async (req, res) => {
const { ghost_name, type, content } = req.body;
if (!content?.trim()) return res.status(400).json({ error: 'Inhalt fehlt' });
if (!['tip', 'edit', 'new'].includes(type)) return res.status(400).json({ error: 'Ungültiger Typ' });
if (!['tip','edit','new'].includes(type)) return res.status(400).json({ error: 'Ungültiger Typ' });
try {
await db.query(