mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-30 16:33:16 +00:00
refactor(trips): leaving a trip tidies its journal link in the roster's own repository
The departure port needed a global binding that every suite building TripMembersModule without AppModule lacked. The roster's repository now deletes the leaver's row on the trip's journal link itself (leaveJournalLink), inside the transaction that removes the member: no edge into journey, no DI, no test stub, and the eight suites the stub touched are back as they were. The schema inventory tests count the two new tables and their NOT NULL columns, the legacy step map lists the migration as post-legacy, and the TJL scenes give their users numbered names so cases sharing one database do not collide.
This commit is contained in:
@@ -214,15 +214,6 @@ export class TripJournalLinksRepository extends TrekRepository<TripJournalLinks>
|
||||
.execute();
|
||||
}
|
||||
|
||||
/** Takes one person off the trip's link, as when they leave the trip. */
|
||||
async deleteMember(tripId: number, userId: number): Promise<void> {
|
||||
await this.kysely<TripJournalLinkKyselyDB>()
|
||||
.deleteFrom('trip_journal_link_members')
|
||||
.where('link_id', 'in', this.linkIdOf(tripId))
|
||||
.where('user_id', '=', userId)
|
||||
.execute();
|
||||
}
|
||||
|
||||
/** Everyone a journal's links let in, for its live updates. */
|
||||
async linkRecipientUserIds(journeyId: number): Promise<number[]> {
|
||||
const rows = await linkReach(this.kysely<TripJournalLinkKyselyDB>())
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { caseWhenEquals, coalesce } from '../dialect/sql-functions';
|
||||
import type { TripMembers } from '../entities/TripMembers.entity';
|
||||
import { Trips } from '../entities/Trips.entity';
|
||||
import type { DB } from '../kysely/db';
|
||||
import { TrekRepository } from './_shared/trek-repository';
|
||||
|
||||
/**
|
||||
@@ -266,6 +267,22 @@ export class TripMembersRepository extends TrekRepository<TripMembers> {
|
||||
await this.qb('m').delete().where({ trip: trip_id }).andWhere('m.user_id = ?', [user_id]).execute('run');
|
||||
}
|
||||
|
||||
/**
|
||||
* Takes someone who left the trip off its journal link, so coming back later
|
||||
* does not quietly reopen the journal. Their access already ended with the
|
||||
* membership (the link's reach requires it); this tidies the row. Here rather
|
||||
* than in the journey domain because leaving is the roster's to finish, and
|
||||
* reaching into journey from the roster closed a cycle between the two.
|
||||
*/
|
||||
async leaveJournalLink(tripId: number, userId: number): Promise<void> {
|
||||
const db = this.kysely<Pick<DB, 'trip_journal_links' | 'trip_journal_link_members'>>();
|
||||
await db
|
||||
.deleteFrom('trip_journal_link_members')
|
||||
.where('user_id', '=', userId)
|
||||
.where('link_id', 'in', db.selectFrom('trip_journal_links').select('id').where('trip_id', '=', tripId))
|
||||
.execute();
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Plan 3c Task 7 (`trips.rpc.ts::members`) — additive: no other repository
|
||||
// is rooted at `trip_members` joined to `users`, and RP3's shape is
|
||||
|
||||
@@ -53,7 +53,6 @@ import { DawarichModule } from './integrations/dawarich.module';
|
||||
import { JourneyAccessModule } from './journey/journey-access.module';
|
||||
import { JourneyModule } from './journey/journey.module';
|
||||
import { TripJournalLinkModule } from './journey/trip-journal-link.module';
|
||||
import { TripMemberDepartureModule } from './journey/trip-member-departure.module';
|
||||
import { LlmParseModule } from './llm-parse/llm-parse.module';
|
||||
import { ManagedExtModule } from './managed/managed-ext.module';
|
||||
import { MapsModule } from './maps/maps.module';
|
||||
@@ -169,7 +168,6 @@ import { APP_FILTER, APP_GUARD, APP_INTERCEPTOR, APP_PIPE } from '@nestjs/core';
|
||||
DawarichModule,
|
||||
JourneyModule,
|
||||
TripJournalLinkModule,
|
||||
TripMemberDepartureModule,
|
||||
CollectionsModule,
|
||||
ShareModule,
|
||||
TripInviteModule,
|
||||
|
||||
@@ -1,16 +0,0 @@
|
||||
/**
|
||||
* What the trip roster tells the rest of the app when someone leaves a trip.
|
||||
*
|
||||
* A port rather than the journal link service itself: the journey domain
|
||||
* already depends on the trip roster through others, so reaching into it from
|
||||
* the roster closed a cycle. It lives in common/ because either domain owning
|
||||
* it would draw that edge again. The journey domain binds the token
|
||||
* (TripMemberDepartureModule), and the roster calls it inside the transaction
|
||||
* that removes the member.
|
||||
*/
|
||||
export const TRIP_MEMBER_DEPARTURE = Symbol('TRIP_MEMBER_DEPARTURE');
|
||||
|
||||
export interface TripMemberDeparture {
|
||||
/** `userId` is off the trip now; whatever they held through it goes too. Runs in the caller's transaction. */
|
||||
memberLeft(tripId: number, userId: number): Promise<void>;
|
||||
}
|
||||
@@ -14,10 +14,7 @@ import { Module } from '@nestjs/common';
|
||||
|
||||
/**
|
||||
* A trip showing one journal from the Journey addon: the link, its routes and
|
||||
* its MCP tools. Its own module rather than part of JourneyModule, so the
|
||||
* binding of the trip roster's departure port (TripMemberDepartureModule) does
|
||||
* not pull in the whole journey surface (uploads, memories, both photo
|
||||
* providers).
|
||||
* its MCP tools.
|
||||
*/
|
||||
@Module({
|
||||
imports: [
|
||||
|
||||
@@ -4,7 +4,6 @@ import type { JourneyContributorsRepository } from '../../db/repositories/Journe
|
||||
import type { TripJournalLinksRepository, TripPersonRow } from '../../db/repositories/TripJournalLinks.repository';
|
||||
import { avatarUrl } from '../common/avatarUrl';
|
||||
import { forbidden, notFound } from '../common/domain-error';
|
||||
import type { TripMemberDeparture } from '../common/trip-member-departure.types';
|
||||
import { UnitOfWork } from '../database/unit-of-work';
|
||||
import { PermissionsService } from '../permissions/permissions.service';
|
||||
import { RealtimeService } from '../realtime/realtime.service';
|
||||
@@ -42,7 +41,7 @@ const NOT_LINKED = 'No journal is linked to this trip';
|
||||
* alone or the journal's owner alone is enough.
|
||||
*/
|
||||
@Injectable()
|
||||
export class TripJournalLinkService implements TripMemberDeparture {
|
||||
export class TripJournalLinkService {
|
||||
constructor(
|
||||
@InjectRepository(TripJournalLinks) private readonly links: TripJournalLinksRepository,
|
||||
@InjectRepository(JourneyContributors) private readonly contributors: JourneyContributorsRepository,
|
||||
@@ -207,13 +206,4 @@ export class TripJournalLinkService implements TripMemberDeparture {
|
||||
this.realtime.broadcast(tripId, 'trip:journal:changed', {}, socketId);
|
||||
return this.get(tripId, actor);
|
||||
}
|
||||
|
||||
/**
|
||||
* Someone left the trip: their place on its link goes too, so coming back
|
||||
* later does not quietly reopen the journal. Their access already ended with
|
||||
* the membership; this only tidies the row. Runs in the caller's transaction.
|
||||
*/
|
||||
async memberLeft(tripId: number, userId: number): Promise<void> {
|
||||
await this.links.deleteMember(tripId, userId);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,18 +0,0 @@
|
||||
import { TRIP_MEMBER_DEPARTURE } from '../common/trip-member-departure.types';
|
||||
import { TripJournalLinkModule } from './trip-journal-link.module';
|
||||
import { TripJournalLinkService } from './trip-journal-link.service';
|
||||
import { Global, Module } from '@nestjs/common';
|
||||
|
||||
/**
|
||||
* Binds the trip roster's TRIP_MEMBER_DEPARTURE port to TripJournalLinkService,
|
||||
* so someone leaving a trip also leaves its journal link. Global so
|
||||
* TripMembersModule resolves it without importing the journey domain;
|
||||
* AppModule imports it next to the roster.
|
||||
*/
|
||||
@Global()
|
||||
@Module({
|
||||
imports: [TripJournalLinkModule],
|
||||
providers: [{ provide: TRIP_MEMBER_DEPARTURE, useExisting: TripJournalLinkService }],
|
||||
exports: [TRIP_MEMBER_DEPARTURE],
|
||||
})
|
||||
export class TripMemberDepartureModule {}
|
||||
@@ -25,9 +25,6 @@ import { Module } from '@nestjs/common';
|
||||
* `DatabaseModule` is gone (Plan 4 Task 4) — `TripMembersService` is fully
|
||||
* repository-backed (`getTripForViewer` → `TripsRepository.findForViewer`,
|
||||
* `canAccessTrip` → `TripsRepository.findAccessible`).
|
||||
*
|
||||
* Leaving a trip also leaves its journal link, through the TRIP_MEMBER_DEPARTURE
|
||||
* port the journey domain binds globally (TripMemberDepartureModule).
|
||||
*/
|
||||
@Module({
|
||||
imports: [
|
||||
|
||||
@@ -10,13 +10,12 @@ import { UserCleanupService } from '../auth/user-cleanup.service';
|
||||
import { BudgetService } from '../budget/budget.service';
|
||||
import { avatarUrl } from '../common/avatarUrl';
|
||||
import { NotFoundError, ValidationError } from '../common/domain-errors';
|
||||
import { TRIP_MEMBER_DEPARTURE, type TripMemberDeparture } from '../common/trip-member-departure.types';
|
||||
import { UnitOfWork } from '../database/unit-of-work';
|
||||
import { NotificationsService } from '../notifications/notifications.service';
|
||||
import { PermissionsService } from '../permissions/permissions.service';
|
||||
import { RealtimeService } from '../realtime/realtime.service';
|
||||
import { InjectRepository } from '@mikro-orm/nestjs';
|
||||
import { Inject, Injectable } from '@nestjs/common';
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import type { TrekWsPayload, TrekWsTripEventName } from '@trek/shared';
|
||||
|
||||
import { randomUUID } from 'crypto';
|
||||
@@ -80,7 +79,6 @@ export class TripMembersService {
|
||||
private readonly permissions: PermissionsService,
|
||||
private readonly realtime: RealtimeService,
|
||||
private readonly notifications: NotificationsService,
|
||||
@Inject(TRIP_MEMBER_DEPARTURE) private readonly departure: TripMemberDeparture,
|
||||
private readonly uow: UnitOfWork,
|
||||
@InjectRepository(Trips) private readonly tripsRepo: TripsRepository,
|
||||
@InjectRepository(TripMembers) private readonly tripMembersRepo: TripMembersRepository,
|
||||
@@ -203,7 +201,7 @@ export class TripMembersService {
|
||||
// must not quietly reopen it.
|
||||
await this.uow.transactional(async () => {
|
||||
await this.tripMembersRepo.remove(tripId, targetUserId);
|
||||
await this.departure.memberLeft(tripId, targetUserId);
|
||||
await this.tripMembersRepo.leaveJournalLink(tripId, targetUserId);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user