mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-27 23:27:31 +00:00
refactor(nest): inject DatabaseService in access-check services and controllers
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import { Controller, Get, Param, Req, UseGuards } from '@nestjs/common';
|
||||
import type { Request } from 'express';
|
||||
import { canAccessTrip } from '../../db/database';
|
||||
import { DatabaseService } from '../database/database.service';
|
||||
import { JwtAuthGuard } from '../auth/jwt-auth.guard';
|
||||
import { pluginsEnabled } from './kill-switch';
|
||||
import { PluginRuntimeService } from './plugin-runtime.service';
|
||||
@@ -74,7 +74,10 @@ function normalize(pluginId: string, raw: unknown): PdfSection[] {
|
||||
@Controller('api/pdf-sections')
|
||||
@UseGuards(JwtAuthGuard)
|
||||
export class PdfSectionsController {
|
||||
constructor(private readonly runtime: PluginRuntimeService) {}
|
||||
constructor(
|
||||
private readonly runtime: PluginRuntimeService,
|
||||
private readonly dbs: DatabaseService,
|
||||
) {}
|
||||
|
||||
@Get(':tripId')
|
||||
async get(
|
||||
@@ -84,7 +87,7 @@ export class PdfSectionsController {
|
||||
if (!pluginsEnabled()) return { sections: [] };
|
||||
const tripId = Number(tripIdRaw);
|
||||
const userId = req.user?.id;
|
||||
if (!Number.isFinite(tripId) || userId == null || !canAccessTrip(tripId, userId)) return { sections: [] };
|
||||
if (!Number.isFinite(tripId) || userId == null || !this.dbs.canAccessTrip(tripId, userId)) return { sections: [] };
|
||||
|
||||
const ids = this.runtime.providersOf('pdfSectionProvider');
|
||||
const perProvider = await Promise.all(
|
||||
|
||||
Reference in New Issue
Block a user