From 98529bc84ce9910abcdcbce2f8c05f2a70315b5e Mon Sep 17 00:00:00 2001 From: Maurice Date: Tue, 17 Nov 2026 11:41:02 +0100 Subject: [PATCH] fix(db): return the traveller owner flag as a number on Postgres The owner and member branches of listTravellerUsernames selected bound values, which Postgres resolves to text in a UNION column, so the public API reported every traveller as owner: false. The literals are written into the statement as integers now. --- server/src/db/repositories/Trips.repository.ts | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/server/src/db/repositories/Trips.repository.ts b/server/src/db/repositories/Trips.repository.ts index b4d5c9b8c..3a74cdf48 100644 --- a/server/src/db/repositories/Trips.repository.ts +++ b/server/src/db/repositories/Trips.repository.ts @@ -792,20 +792,21 @@ export class TripsRepository extends TrekRepository { * FROMs has no single alias to chain a `.select()`/`.where()` off (unlike * `accessibleTripsQuery`'s single-FROM join), so this is Kysely * (`this.kysely()`, the same escape hatch `tripSelectQuery`'s own - * docstring documents) — `eb.val(1)`/`eb.val(0)` for the - * two literal branches, the same construct `tripSelectQuery`'s `NULL AS - * feed_token` already uses in this file. + * docstring documents). The two literal branches are `eb.lit(1)`/`eb.lit(0)`, + * written into the statement as integers: a bound `eb.val(1)` reaches + * Postgres untyped, and a UNION column of untyped values comes back as + * text ('1'), which the public API's `is_owner === 1` never matched. */ async listTravellerUsernames(trip_id: number): Promise { const owner = this.kysely() .selectFrom('trips as t') .innerJoin('users as u', 'u.id', 't.user_id') - .select((eb) => ['u.username as username', eb.val(1).as('is_owner')]) + .select((eb) => ['u.username as username', eb.lit(1).as('is_owner')]) .where('t.id', '=', trip_id); const member = this.kysely() .selectFrom('trip_members as m') .innerJoin('users as u', 'u.id', 'm.user_id') - .select((eb) => ['u.username as username', eb.val(0).as('is_owner')]) + .select((eb) => ['u.username as username', eb.lit(0).as('is_owner')]) .where('m.trip_id', '=', trip_id); const rows = await owner.unionAll(member).orderBy('is_owner', 'desc').execute(); return rows as TravellerUsernameRow[];