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

This commit is contained in:
jubnl
2026-07-25 18:15:04 +02:00
parent def6b84938
commit fbe200424d
36 changed files with 345 additions and 223 deletions
+9 -3
View File
@@ -1,5 +1,5 @@
import { Injectable } from '@nestjs/common';
import { db, canAccessTrip } from '../../db/database';
import { DatabaseService } from '../database/database.service';
import { broadcast } from '../../websocket';
import { checkPermission } from '../../services/permissions';
import type { User } from '../../types';
@@ -22,8 +22,14 @@ import { searchUnsplashPhotos, getUnsplashKey } from '../../services/unsplashSer
*/
@Injectable()
export class TripsService {
constructor(private readonly dbs: DatabaseService) {}
private get db() {
return this.dbs.connection;
}
canAccessTrip(tripId: string, userId: number) {
return canAccessTrip(tripId, userId) as { user_id: number } | null | undefined;
return this.dbs.canAccessTrip(tripId, userId) as { user_id: number } | null | undefined;
}
can(action: string, role: string, ownerId: number | null, userId: number, isMember: boolean): boolean {
@@ -84,7 +90,7 @@ export class TripsService {
/** Re-read a freshly copied trip in list shape (mirrors the route's TRIP_SELECT query). */
getCopiedTrip(newTripId: number, userId: number) {
return db.prepare(`${tripSvc.TRIP_SELECT} WHERE t.id = :tripId`).get({ userId, tripId: newTripId });
return this.db.prepare(`${tripSvc.TRIP_SELECT} WHERE t.id = :tripId`).get({ userId, tripId: newTripId });
}
listMembers(tripId: string, ownerId: number) {