mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-10-19 21:46:49 +00:00
939452f9d8
* refactor(server): route every trip-access check through DatabaseService
Twelve Nest services carry the same verifyTripAccess/canEdit pair. Six already
asked DatabaseService.canAccessTrip; the other six went through
services/tripAccess, a nine-line re-export of the identical function. Same
query, same result, two ways to reach it.
All twelve now take the injected route, so services/tripAccess is gone.
The bigger duplication was in the types. Thirteen files declared their own
`Trip` for the same return value, in three different shapes:
NonNullable<ReturnType<typeof verifyTripAccess>> 6x
{ user_id: number } 4x
TripAccess 3x
The narrow one is why assignments, days, places and accommodations all wrote
`as Trip | null | undefined` on the call — the cast existed to shrink
TripAccess down to a local type that was never meant to differ from it. All
thirteen now say TripAccess, and the four casts are gone with no other change.
middleware/tripAccess.ts goes too: it was already dead in production — nothing
under src/ imported requireTripAccess or requireTripOwner, only comments in the
services that had absorbed them. Its test went with it.
* refactor(server): fold the query helpers and trip joins into the container
Two more legacy files whose only reason for staying outside the container was
that they predated it.
services/queryHelpers.ts held five exports doing two different jobs. Three are
the batch loaders that keep the list endpoints off N+1 queries — they hit the
database and are now QueryHelpersService over the injected connection, imported
by assignments, days, places and share. The other two, formatAssignmentWithPlace
and ratingAggregate, touch no database at all; they sat next to the loaders only
because the loaders were free functions too. Those stay free functions, in
common/rowShape.ts.
The README note on the assignments service claimed the loaders had to stay in
services/ because the day, share and place services were unmigrated. All three
have since moved, so the reason is gone.
services/tripMembership.ts becomes TripMembershipService in its own module. It
could have folded into auth or trip-invite, but both call it — as do oidc and
the plugin RPC host — and putting it in either would have made AuthModule and
TripInviteModule import each other.
Neither module is @Global, matching PermissionsModule: e2e TestingModules
resolve them transitively through each consumer's explicit import.
Test seams changed shape accordingly. Two path mocks of services/tripMembership
became injected stubs; the trip-invite e2e overrides the provider in the
container instead. The oidc test keeps the real implementation, which is what
OIDC-SVC-045 was always asserting.
ratingAggregate moved out of the ungated services/ tree into the coverage-gated
one, so it gets the direct tests it never had — as does the tags/participants
pass-through, which two long-dead fixture variables in the moved test file had
been waiting for.
Also drops four stale comments that outlived their subject: the requireTripAccess
middleware they pointed at was deleted in the previous commit.
86 lines
4.6 KiB
TypeScript
86 lines
4.6 KiB
TypeScript
import { DatabaseService } from '../../src/nest/database/database.service';
|
|
import { PluginRuntimeService } from '../../src/nest/plugins/plugin-runtime.service';
|
|
import type { PluginRegistryService } from '../../src/nest/plugins/registry/registry.service';
|
|
import { PluginHostDepsFactory } from '../../src/nest/plugins/host/plugin-host-deps.factory';
|
|
import { PluginOAuthService } from '../../src/nest/plugins/plugin-oauth.service';
|
|
import { BudgetService } from '../../src/nest/budget/budget.service';
|
|
import { ExchangeRatesService } from '../../src/nest/budget/exchange-rates.service';
|
|
import { ReservationsService } from '../../src/nest/reservations/reservations.service';
|
|
import { TagsService } from '../../src/nest/tags/tags.service';
|
|
import { CategoriesService } from '../../src/nest/categories/categories.service';
|
|
import { TodoService } from '../../src/nest/todo/todo.service';
|
|
import { PackingService } from '../../src/nest/packing/packing.service';
|
|
import { DayNotesService } from '../../src/nest/days/day-notes.service';
|
|
import { DaysService } from '../../src/nest/days/days.service';
|
|
import { AssignmentsService } from '../../src/nest/assignments/assignments.service';
|
|
import { LlmConfigResolver } from '../../src/nest/llm-parse/llm-config.resolver';
|
|
import { SettingsService } from '../../src/nest/settings/settings.service';
|
|
import { FilesService } from '../../src/nest/files/files.service';
|
|
import { CollabService } from '../../src/nest/collab/collab.service';
|
|
import { VacayService } from '../../src/nest/vacay/vacay.service';
|
|
import { TripsService } from '../../src/nest/trips/trips.service';
|
|
import { PlacesService } from '../../src/nest/places/places.service';
|
|
import { CollectionsService } from '../../src/nest/collections/collections.service';
|
|
import { AtlasService } from '../../src/nest/atlas/atlas.service';
|
|
import { NotificationsService } from '../../src/nest/notifications/notifications.service';
|
|
import { MapsService } from '../../src/nest/maps/maps.service';
|
|
import { PermissionsService } from '../../src/nest/permissions/permissions.service';
|
|
import { AuditService } from '../../src/nest/audit/audit.service';
|
|
import { AddonsService } from '../../src/nest/addons/addons.service';
|
|
import { RealtimeService } from '../../src/nest/realtime/realtime.service';
|
|
import { QueryHelpersService } from '../../src/nest/query-helpers/query-helpers.service';
|
|
|
|
/**
|
|
* Hand-wired counterpart of the PluginsModule DI graph for no-Nest tests
|
|
* (same pattern as mcp-test-controllers.ts): real domain services over the
|
|
* test DB, so runtime tests exercise the same wiring production gets from
|
|
* the container.
|
|
*/
|
|
export function createHostDepsFactory(dbs: DatabaseService): PluginHostDepsFactory {
|
|
const permissions = new PermissionsService(dbs);
|
|
const exchangeRates = new ExchangeRatesService();
|
|
const realtime = new RealtimeService();
|
|
const budget = new BudgetService(dbs, permissions, exchangeRates, realtime);
|
|
const addons = new AddonsService(dbs);
|
|
const queryHelpers = new QueryHelpersService(dbs);
|
|
const todos = new TodoService(dbs, permissions, realtime);
|
|
const packing = new PackingService(dbs, permissions, realtime);
|
|
const files = new FilesService(dbs, permissions, realtime);
|
|
const reservations = new ReservationsService(dbs, permissions, budget, realtime);
|
|
const collab = new CollabService(dbs, permissions, realtime);
|
|
const vacay = new VacayService(dbs, realtime);
|
|
const days = new DaysService(dbs, permissions, realtime, queryHelpers);
|
|
const places = new PlacesService(dbs, permissions, realtime, new MapsService(dbs), queryHelpers);
|
|
return new PluginHostDepsFactory(
|
|
budget,
|
|
reservations,
|
|
new TagsService(dbs),
|
|
new CategoriesService(dbs),
|
|
todos,
|
|
packing,
|
|
new PluginOAuthService(dbs),
|
|
new DayNotesService(dbs, permissions, realtime),
|
|
new AssignmentsService(dbs, permissions, realtime, queryHelpers),
|
|
new LlmConfigResolver(new SettingsService(dbs), dbs, addons),
|
|
dbs,
|
|
files,
|
|
collab,
|
|
vacay,
|
|
days,
|
|
permissions,
|
|
exchangeRates,
|
|
addons,
|
|
realtime,
|
|
new TripsService(dbs, todos, packing, files, reservations, days, permissions, budget, collab, vacay, realtime, places),
|
|
places,
|
|
new CollectionsService(dbs, permissions, realtime),
|
|
new AtlasService(dbs),
|
|
new NotificationsService(dbs, realtime),
|
|
);
|
|
}
|
|
|
|
/** A PluginRuntimeService constructed the way Nest would: with a real host-deps factory. */
|
|
export function createPluginRuntime(dbs: DatabaseService, registry?: PluginRegistryService): PluginRuntimeService {
|
|
return new PluginRuntimeService(dbs, new AuditService(dbs), new AddonsService(dbs), registry, createHostDepsFactory(dbs));
|
|
}
|