mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-26 06:37:33 +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';
|
||||
@@ -145,7 +145,10 @@ function normalize(pluginId: string, raw: unknown): MapLayer[] {
|
||||
@Controller('api/map-layers')
|
||||
@UseGuards(JwtAuthGuard)
|
||||
export class MapLayersController {
|
||||
constructor(private readonly runtime: PluginRuntimeService) {}
|
||||
constructor(
|
||||
private readonly runtime: PluginRuntimeService,
|
||||
private readonly dbs: DatabaseService,
|
||||
) {}
|
||||
|
||||
@Get(':tripId')
|
||||
async get(
|
||||
@@ -155,7 +158,7 @@ export class MapLayersController {
|
||||
if (!pluginsEnabled()) return { layers: [] };
|
||||
const tripId = Number(tripIdRaw);
|
||||
const userId = req.user?.id;
|
||||
if (!Number.isFinite(tripId) || userId == null || !canAccessTrip(tripId, userId)) return { layers: [] };
|
||||
if (!Number.isFinite(tripId) || userId == null || !this.dbs.canAccessTrip(tripId, userId)) return { layers: [] };
|
||||
|
||||
const ids = this.runtime.providersOf('mapLayerProvider');
|
||||
const perProvider = await Promise.all(
|
||||
|
||||
Reference in New Issue
Block a user