- discord-gateway: 74 lint errors -> 0 (format, import sorting, unused imports/vars, dead breath var) - backend: format + sort imports (11 warnings left: noExplicitAny) - frontend: remove unused imports, drop dead breathing var, fix useExhaustiveDependencies (scroll keyed on messages), a11y biome-ignore for drag surface + stopPropagation container (mouse-only gestures) - remaining warnings are false positives: index keys on static lists, <img> in static export (next/image unsupported), noExplicitAny tsc --noEmit clean on all 3 services; vitest green (60+36).
51 lines
1.5 KiB
TypeScript
51 lines
1.5 KiB
TypeScript
import { and, desc, eq, ilike, type SQL } from "drizzle-orm";
|
|
import { getDatabase } from "../../shared/database/index.js";
|
|
import { pgMessagesTable } from "../../shared/index.js";
|
|
import { createChildLogger } from "../../shared/logger/index.js";
|
|
import {
|
|
type MappedMessage,
|
|
mapMessageRow,
|
|
} from "../../shared/utils/messageMapper.js";
|
|
|
|
const logger = createChildLogger("analysis.repository");
|
|
|
|
export interface AnalysisSearchQuery {
|
|
q?: string;
|
|
channelId?: string;
|
|
guildId?: string;
|
|
limit?: number;
|
|
}
|
|
|
|
// AnalysisSearchResult is identical to MappedMessage — reuse the shared mapper
|
|
export type AnalysisSearchResult = MappedMessage;
|
|
|
|
export class AnalysisRepository {
|
|
async search(query: AnalysisSearchQuery): Promise<AnalysisSearchResult[]> {
|
|
const db = getDatabase();
|
|
const { q = "", channelId, guildId, limit = 20 } = query;
|
|
|
|
logger.debug({ q, channelId, guildId, limit }, "Searching analysis");
|
|
|
|
const conditions: SQL[] = [ilike(pgMessagesTable.content, `%${q}%`)];
|
|
|
|
if (guildId) {
|
|
conditions.push(eq(pgMessagesTable.guild_id, guildId));
|
|
}
|
|
|
|
if (channelId) {
|
|
conditions.push(eq(pgMessagesTable.channel_id, channelId));
|
|
}
|
|
|
|
const rows = await db
|
|
.select()
|
|
.from(pgMessagesTable)
|
|
.where(and(...conditions))
|
|
.orderBy(desc(pgMessagesTable.created_at))
|
|
.limit(limit);
|
|
|
|
return rows.map((r) => mapMessageRow(r as Record<string, unknown>));
|
|
}
|
|
}
|
|
|
|
export const analysisRepository = new AnalysisRepository();
|