refactor(nest): inject DatabaseService in db-using controllers

This commit is contained in:
jubnl
2026-07-25 18:15:15 +02:00
parent fbe200424d
commit dd2c2d6668
16 changed files with 74 additions and 36 deletions
@@ -1,6 +1,6 @@
import { Controller, Get, Query, Req, UseGuards } from '@nestjs/common';
import type { Request } from 'express';
import { db } from '../../db/database';
import { DatabaseService } from '../database/database.service';
import { JwtAuthGuard } from '../auth/jwt-auth.guard';
import { pluginsEnabled } from './kill-switch';
import { readAuditForUser } from './host/plugin-audit';
@@ -18,6 +18,8 @@ import { readAuditForUser } from './host/plugin-audit';
@Controller('api/plugin-activity')
@UseGuards(JwtAuthGuard)
export class PluginActivityController {
constructor(private readonly dbs: DatabaseService) {}
@Get()
mine(@Req() req: Request & { user?: { id: number } }, @Query('limit') limitRaw?: string): { activity: unknown[] } {
if (!pluginsEnabled()) return { activity: [] };
@@ -26,6 +28,6 @@ export class PluginActivityController {
// Math.floor so a non-integer (e.g. ?limit=2.5) can't reach SQLite's LIMIT and 500;
// Math.floor(NaN) stays NaN so the `|| 200` fallback still applies.
const limit = Math.min(Math.max(Math.floor(Number(limitRaw)) || 200, 1), 500);
return { activity: readAuditForUser(db, userId, limit) };
return { activity: readAuditForUser(this.dbs.connection, userId, limit) };
}
}