mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-10-20 14:06:27 +00:00
refactor(nest): inject DatabaseService in db-using controllers
This commit is contained in:
@@ -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) };
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user