feat(backend): implement all missing endpoints, real analytics queries, and WebSocket server

- Replace stub analytics.repository.ts with real PostgreSQL queries using pg.Pool
- Add /api/guilds, /api/config, /api/auth/login, /api/ui-state (GET/POST)
- Add /api/review, /api/recordings, /api/analysis/search
- Add /api/messages/:id/reanalyze endpoint
- Add /api/analytics/heatmap and /api/analytics/topics
- Implement media routes (stub responses, backend has no Discord voice client)
- Add WebSocket server at /ws with heartbeat and broadcast functions
- Fix analytics route paths to match frontend contract (dual paths for backward compat)
- Export getPool() from database module for raw SQL queries
- Register all new routers in app.ts

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
MythEclipse
2026-06-02 00:11:29 +07:00
co-authored by Claude Opus 4.8
parent 5a094c926a
commit 9b41eb9c12
24 changed files with 1205 additions and 87 deletions
@@ -1,9 +1,94 @@
import { createChildLogger } from "../../shared/logger/index.js";
import { getDatabase } from "../../shared/database/index.js";
const logger = createChildLogger("voice.service");
export class VoiceService {
// TODO: Implement voice service methods
export interface Guild {
id: string;
name: string;
}
export const voiceService = new VoiceService();
export interface Channel {
id: string;
name: string;
type: "voice" | "text";
}
export interface VoiceStatus {
connected: boolean;
guildId: string | null;
channelId: string | null;
users: Array<{ id: string; name: string }>;
}
/**
* Get guilds from database (distinct guild_id from messages).
*/
export async function getGuilds(): Promise<Guild[]> {
const db = getDatabase();
const result = await db.execute(
"SELECT DISTINCT guild_id FROM messages ORDER BY guild_id",
);
if (!result?.rows?.length) {
return [];
}
return result.rows.map((row: Record<string, unknown>) => ({
id: String(row.guild_id ?? ""),
name: `Guild ${String(row.guild_id).slice(0, 8)}`,
}));
}
/**
* Get text channels from database (distinct channel_id for a guild).
*/
export async function getTextChannels(guildId: string): Promise<Channel[]> {
const db = getDatabase();
const result = await db.execute(
`SELECT DISTINCT channel_id FROM messages WHERE guild_id = '${guildId.replace(/'/g, "''")}' ORDER BY channel_id`,
);
if (!result?.rows?.length) {
return [];
}
return result.rows.map((row: Record<string, unknown>) => ({
id: String(row.channel_id ?? ""),
name: `Channel ${String(row.channel_id).slice(0, 8)}`,
type: "text" as const,
}));
}
/**
* Get voice channels — not available via API-only backend.
*/
export async function getVoiceChannels(_guildId: string): Promise<Channel[]> {
return [];
}
/**
* Get current voice connection status.
*/
export function getVoiceStatus(): VoiceStatus {
return {
connected: false,
guildId: null,
channelId: null,
users: [],
};
}
/**
* Connect to a voice channel — not supported via API-only backend.
*/
export async function connectVoice(
_guildId: string,
_channelId: string,
): Promise<VoiceStatus> {
return getVoiceStatus();
}
/**
* Disconnect from voice — not supported via API-only backend.
*/
export async function disconnectVoice(): Promise<VoiceStatus> {
return getVoiceStatus();
}