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
+35
View File
@@ -0,0 +1,35 @@
/**
* Global broadcast functions for WebSocket events.
*
* These are assigned by ws/server.ts when the WebSocket server initializes.
* Other modules call them to push real-time events to connected frontend clients.
*
* Usage:
* import { broadcastMessageCreated } from "../ws/broadcast.js";
* broadcastMessageCreated(messageData);
*/
type BroadcastFn = (data: unknown) => void;
// Extend globalThis with broadcast function types
declare global {
// biome-ignore lint/suspicious/noAssignInExpressions: intentional global broadcast registry
var broadcastMessageCreated: BroadcastFn | undefined;
var broadcastMessageUpdated: BroadcastFn | undefined;
var broadcastMessageDeleted: BroadcastFn | undefined;
var broadcastAttachmentUploaded: BroadcastFn | undefined;
}
const noop: BroadcastFn = () => {};
export const broadcastMessageCreated: BroadcastFn = (...args) =>
(globalThis.broadcastMessageCreated ?? noop)(...args);
export const broadcastMessageUpdated: BroadcastFn = (...args) =>
(globalThis.broadcastMessageUpdated ?? noop)(...args);
export const broadcastMessageDeleted: BroadcastFn = (...args) =>
(globalThis.broadcastMessageDeleted ?? noop)(...args);
export const broadcastAttachmentUploaded: BroadcastFn = (...args) =>
(globalThis.broadcastAttachmentUploaded ?? noop)(...args);