From 4a074ec93cccfd743f83ecee668f576f5f6ac52a Mon Sep 17 00:00:00 2001 From: Maurice Date: Sun, 18 Oct 2026 18:54:02 +0200 Subject: [PATCH] refactor(journey): the link role from the generated entity, not a second union TripJournalLinksRepository spelled 'viewer' | 'editor' by hand while the generated entity exports the same roles, which knip then counted as an unused export. The repository now derives its type and values from the entity. --- .../repositories/TripJournalLinks.repository.ts | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/server/src/db/repositories/TripJournalLinks.repository.ts b/server/src/db/repositories/TripJournalLinks.repository.ts index 98af31603..1f5dcef5b 100644 --- a/server/src/db/repositories/TripJournalLinks.repository.ts +++ b/server/src/db/repositories/TripJournalLinks.repository.ts @@ -1,3 +1,7 @@ +import { + TripJournalLinkMembersRole, + type TTripJournalLinkMembersRole, +} from '../entities/TripJournalLinkMembers.entity'; import type { TripJournalLinks } from '../entities/TripJournalLinks.entity'; import type { DB } from '../kysely/db'; import { TrekRepository } from './_shared/trek-repository'; @@ -10,7 +14,10 @@ export type TripJournalLinkKyselyDB = Pick< 'trip_journal_links' | 'trip_journal_link_members' | 'trips' | 'trip_members' | 'journeys' | 'users' >; -export type TripJournalLinkRole = 'viewer' | 'editor'; +/** The role a link gives, as the migration's CHECK and the generated entity spell it. */ +export type TripJournalLinkRole = TTripJournalLinkMembersRole; + +const { EDITOR, VIEWER } = TripJournalLinkMembersRole; /** A trip's link with the journal it shows, as the settings dialog reads it. */ export interface TripJournalLinkRow { @@ -69,8 +76,8 @@ export function linkReach(db: Kysely) { /** The stronger of two link roles; a person linked through two trips gets the better one. */ function strongest(roles: string[]): TripJournalLinkRole | null { - if (roles.includes('editor')) return 'editor'; - return roles.length > 0 ? 'viewer' : null; + if (roles.includes(EDITOR)) return EDITOR; + return roles.length > 0 ? VIEWER : null; } /** The role a person holds on a journal through any trip's link, or null when none lets them in. */ @@ -139,7 +146,7 @@ export class TripJournalLinksRepository extends TrekRepository .where('l.trip_id', '=', tripId) .orderBy('u.username', 'asc') .execute(); - return rows.map((r) => ({ ...r, role: r.role === 'editor' ? 'editor' : 'viewer' })); + return rows.map((r) => ({ ...r, role: r.role === EDITOR ? EDITOR : VIEWER })); } /** Everyone on the trip, its owner first, with what the member picker shows of them. */