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:
Maurice
2026-10-18 20:02:09 +02:00
parent 33c5c7decc
commit 48d573c60d
21 changed files with 51 additions and 114 deletions
@@ -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