mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-27 23:27:31 +00:00
refactor(trip-membership): domains ask TripAccessService who may see a trip
Thirty services, controllers, MCP tools and RPC handlers outside the trips domain injected TripsRepository for one call, findAccessible. They now inject TripAccessService from the trip-membership leaf, in the same constructor slot under the same field name; it answers with the same access row (or undefined) and binds the id exactly as given, so each caller keeps its own coercion and its own 404, 403 or tool error.
This commit is contained in:
@@ -7,6 +7,7 @@ import type { TripsRepository } from '../../../src/db/repositories/Trips.reposit
|
||||
import type { PermissionsService } from '../../../src/nest/permissions/permissions.service';
|
||||
import type { AddonsService } from '../../../src/nest/addons/addons.service';
|
||||
import type { User } from '../../../src/types';
|
||||
import { TripAccessService } from '../../../src/nest/trip-membership/trip-access.service';
|
||||
|
||||
const user = { id: 3, role: 'user' } as User;
|
||||
const photo = (name = 'r.jpg') => ({ originalname: name, buffer: Buffer.from('x') } as Express.Multer.File);
|
||||
@@ -17,7 +18,7 @@ function make(over: { readsImages?: boolean; trip?: unknown; addon?: boolean; al
|
||||
const c = new ReceiptScanController(
|
||||
{ startReceipt } as unknown as ImportJobsService,
|
||||
{ readsImages: vi.fn(async () => over.readsImages ?? true) } as unknown as LlmParseService,
|
||||
{ findAccessible: vi.fn(async () => ('trip' in over ? over.trip : { user_id: 5 })) } as unknown as TripsRepository,
|
||||
new TripAccessService({ findAccessible: vi.fn(async () => ('trip' in over ? over.trip : { user_id: 5 })) } as unknown as TripsRepository),
|
||||
{ checkPermission } as unknown as PermissionsService,
|
||||
{ isAddonEnabled: vi.fn(async () => over.addon ?? true) } as unknown as AddonsService,
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user