Merge pull request #3319 from liketrek/codex/trip-tags-desktop-polish

Add custom trip tags and refine the desktop interface
This commit is contained in:
Maurice
2026-12-05 13:26:40 +01:00
committed by GitHub
340 changed files with 3561 additions and 2540 deletions
+2
View File
@@ -65,6 +65,7 @@ export class Trips {
updated_at?: string | null;
reminder_sent_for?: string | null;
costs_mode: TTripsCostsMode & Opt = TripsCostsMode.SPLIT;
tags_json?: string | null;
assistant_attachments_collection = new Collection<AssistantAttachments>(this);
assistant_threads_collection = new Collection<AssistantThreads>(this);
budget_category_order_collection = new Collection<BudgetCategoryOrder>(this);
@@ -146,6 +147,7 @@ export const TripsSchema = defineEntity({
updated_at: p.type(DbTimestampType).nullable().defaultRaw(`CURRENT_TIMESTAMP`),
reminder_sent_for: p.text().nullable(),
costs_mode: p.enum(() => TripsCostsMode).default('split'),
tags_json: p.text().nullable(),
assistant_attachments_collection: () => p.oneToMany(AssistantAttachments).mappedBy('trip').hidden(),
assistant_threads_collection: () => p.oneToMany(AssistantThreads).mappedBy('trip').hidden(),
budget_category_order_collection: () => p.oneToMany(BudgetCategoryOrder).mappedBy('trip').hidden(),
+1
View File
@@ -18,4 +18,5 @@ export interface TripsTable {
updated_at: InsertOptional<string | null>;
reminder_sent_for: InsertOptional<string | null>;
costs_mode: InsertOptional<string>;
tags_json: InsertOptional<string | null>;
}
@@ -0,0 +1,13 @@
import { engineDdl } from '../migration-utils';
import { Migration } from '@mikro-orm/migrations';
export class Migration20200101046650_trips_can_carry_custom_tags extends Migration {
override name = 'Migration20200101046650_trips_can_carry_custom_tags';
override up(): void {
engineDdl(this, {
sqlite: ['ALTER TABLE trips ADD COLUMN tags_json TEXT'],
postgres: ['ALTER TABLE "trips" ADD COLUMN "tags_json" text'],
});
}
}
+19 -38
View File
@@ -6,6 +6,9 @@ import { TrekRepository } from './_shared/trek-repository';
import { tripAccessExpr } from './_shared/trip-access';
import type { DB } from '../kysely/db';
import { toRowId } from '../row-id';
import { decodeTags, encodeTags, type TripDatabaseRow, type TripRawRow } from './tripRows';
export type { TripRawRow } from './tripRows';
/** What a trip-scoped request learns about the trip once access is verified. */
export interface TripAccess {
@@ -14,34 +17,6 @@ export interface TripAccess {
currency: string | null;
}
/**
* `SELECT * FROM trips WHERE id = ?`, every scalar column — the row
* `TripReadModelService.getTripSummary` (TR-B) and, once Task 7 lands,
* `TripsService.getRaw` (TP22) both need, `feed_token` included: the
* `withoutFeedToken()` JS strip that guards the credential stays in the
* SERVICE (TR-B's ruling), so this repository method must hand the column
* back intact for that strip to have something to delete.
*/
export interface TripRawRow {
id: number;
user_id: number;
title: string;
description: string | null;
start_date: string | null;
end_date: string | null;
currency: string | null;
cover_image: string | null;
is_archived: number | null;
reminder_days: number | null;
feed_token: string | null;
created_at: string | null;
updated_at: string | null;
reminder_sent_for: string | null;
costs_mode: TTripsCostsMode;
}
const _tripRawRowKeys: AssertRowKeys<TripRawRow, Trips> = true;
/**
* `TRIP_SELECT`'s output row (inventory §11a) — every `TripRawRow` column
* plus the four computed/joined columns the projection adds. `feed_token`
@@ -350,8 +325,8 @@ export class TripsRepository extends TrekRepository<Trips> {
const row = await this.qb('t')
.select(['t.*'])
.where('t.id = ?', [id])
.execute<TripRawRow | undefined>('get', false);
return row ?? null;
.execute<TripDatabaseRow | undefined>('get', false);
return row ? decodeTags(row) : null;
}
// ---------------------------------------------------------------------------
@@ -405,7 +380,7 @@ export class TripsRepository extends TrekRepository<Trips> {
const id = toRowId(trip_id);
if (id === null) return undefined;
const row = await this.tripSelectQuery(user_id).where('t.id', '=', id).executeTakeFirst();
return row as TripSelectRow | undefined;
return row ? decodeTags(row) as TripSelectRow : undefined;
}
/**
@@ -432,7 +407,7 @@ export class TripsRepository extends TrekRepository<Trips> {
.where('t.id', '=', id)
.where((eb) => tripAccessExpr(eb, 't.user_id', 'm.user_id', user_id))
.executeTakeFirst();
return row as TripSelectRow | undefined;
return row ? decodeTags(row) as TripSelectRow : undefined;
}
/**
@@ -447,7 +422,7 @@ export class TripsRepository extends TrekRepository<Trips> {
.where((eb) => tripAccessExpr(eb, 't.user_id', 'm.user_id', user_id));
if (archived !== null) query = query.where('t.is_archived', '=', archived);
const rows = await query.orderBy('t.created_at', 'desc').execute();
return rows as TripSelectRow[];
return rows.map(decodeTags) as TripSelectRow[];
}
/**
@@ -525,6 +500,7 @@ export class TripsRepository extends TrekRepository<Trips> {
user_id: number;
title: string;
description: string | null;
tags?: string[];
start_date: string | null;
end_date: string | null;
currency: string;
@@ -534,6 +510,7 @@ export class TripsRepository extends TrekRepository<Trips> {
user: input.user_id,
title: input.title,
description: input.description,
...encodeTags(input.tags),
start_date: input.start_date,
end_date: input.end_date,
currency: input.currency,
@@ -562,6 +539,7 @@ export class TripsRepository extends TrekRepository<Trips> {
user_id: number;
title: string;
description: string | null;
tags?: string[];
start_date: string | null;
end_date: string | null;
currency: string | null;
@@ -573,6 +551,7 @@ export class TripsRepository extends TrekRepository<Trips> {
user: input.user_id,
title: input.title,
description: input.description,
...encodeTags(input.tags),
start_date: input.start_date,
end_date: input.end_date,
currency: input.currency,
@@ -605,11 +584,12 @@ export class TripsRepository extends TrekRepository<Trips> {
*/
async updateTripRow(
id: number,
data: Pick<TripRawRow, 'title' | 'description' | 'start_date' | 'end_date' | 'is_archived' | 'cover_image' | 'costs_mode'>
& { currency: string; reminder_days: number },
data: Partial<Pick<TripRawRow, 'title' | 'description' | 'start_date' | 'end_date' | 'is_archived' | 'cover_image' | 'costs_mode'>
& { currency: string; reminder_days: number; tags: string[] }>,
): Promise<void> {
const platform = this.getEntityManager().getPlatform();
await this.nativeUpdate({ id }, { ...data, updated_at: currentTimestamp(platform) });
const { tags, ...fields } = data;
await this.nativeUpdate({ id }, { ...fields, ...encodeTags(tags), updated_at: currentTimestamp(platform) });
}
/** TP35 (`trips.service.ts::updateCoverImage`) — `UPDATE trips SET cover_image=?, updated_at=CURRENT_TIMESTAMP WHERE id=?`. */
@@ -910,10 +890,11 @@ export class TripsRepository extends TrekRepository<Trips> {
* the join can never fan a `t` row out to more than one result row.
*/
async listOwnedOrMember(user_id: number): Promise<TripRawRow[]> {
return await this.accessibleTripsQuery(user_id)
const rows = await this.accessibleTripsQuery(user_id)
.select(['t.*'])
.orderBy({ 't.start_date': 'desc' })
.execute<TripRawRow[]>('all', false);
.execute<TripDatabaseRow[]>('all', false);
return rows.map(decodeTags);
}
/**
+53
View File
@@ -0,0 +1,53 @@
import type { TTripsCostsMode, Trips } from '../entities/Trips.entity';
import type { AssertRowKeys } from './_shared/rows';
import { tripTagNamesSchema, uniqueTripTags } from '@trek/shared';
/**
* `SELECT * FROM trips WHERE id = ?`, every scalar column — the row
* `TripReadModelService.getTripSummary` (TR-B) and, once Task 7 lands,
* `TripsService.getRaw` (TP22) both need, `feed_token` included: the
* `withoutFeedToken()` JS strip that guards the credential stays in the
* SERVICE (TR-B's ruling), so this repository method must hand the column
* back intact for that strip to have something to delete.
*/
export interface TripDatabaseRow {
id: number;
user_id: number;
title: string;
description: string | null;
tags_json: string | null;
start_date: string | null;
end_date: string | null;
currency: string | null;
cover_image: string | null;
is_archived: number | null;
reminder_days: number | null;
feed_token: string | null;
created_at: string | null;
updated_at: string | null;
reminder_sent_for: string | null;
costs_mode: TTripsCostsMode;
}
const _tripRawRowKeys: AssertRowKeys<TripDatabaseRow, Trips> = true;
export type TripRawRow = Omit<TripDatabaseRow, 'tags_json'> & { tags?: string[] };
export function decodeTags<T extends { tags_json: string | null }>({ tags_json, ...row }: T) {
let tags: string[] = [];
if (tags_json) {
try {
const parsed = tripTagNamesSchema.safeParse(JSON.parse(tags_json));
if (parsed.success) tags = parsed.data;
} catch {
// Older import tools may have written invalid JSON. Keep the trip readable.
}
}
return { ...row, tags };
}
export function encodeTags(tags: string[] | undefined): { tags_json?: string | null } {
if (tags === undefined) return {};
const unique = uniqueTripTags(tags);
return { tags_json: unique.length ? JSON.stringify(unique) : null };
}