feat(tours): point a tour at its trip's packing list

A tour can now point at the packing list of its trip, as a whole or at one
of its categories (say "Hiking gear" for a hike), and shows it in its detail.
The new Packing list section reads the list live as the user may see it: the
backpack tile with the item count on its corner and the category's own
colour, how many are packed with a thin progress bar, the first items ticked
off or not with their quantity, how many more there are, and a button that
opens the trip's Lists tab. Who may change the tour links one, changes it or
lets go through a dialog that lists the whole list and every category with
its colour and item count, and writes only on its confirm.

It is a reference, never a copy: the items stay in Packing, are ticked off
and edited there, and each traveller sees in the tour only the items Packing
shows them, so an item kept to oneself never shows through a tour. A
category that is renamed, cleared or only holds items of others reads as
missing, an empty one as empty, a link that could not be read says so with a
retry, and while Lists are switched off the link stays, dimmed, and can
still be let go. Removing the link, or the tour, leaves the list and every
item as they are. Nothing suggests or changes an item by itself.

On the server the link is a row of its own in the tours domain
(tour_packing_links, migration 046110), one per tour and gone with it.
GET, PUT and DELETE /api/trips/:tripId/tours/:placeId/packing-link read it
with the trip and change it with place_edit; linking needs the Lists addon
and, for a category, an item of it the user can see. The writes answer the
tour with its link and tell the trip through tours:changed, so the offline
client queues them as writes of the tour and replays them like one. A copied
trip keeps its tours' links, a tour saved as new or taken over does not.
The MCP tools get_tour_packing, link_tour_packing and unlink_tour_packing run
over the same service and checks; the read also hands the tour's facts as
context for suggesting what to pack, which only becomes an item through the
packing tools. The empty category placeholder now lives in @trek/shared so
both sides leave it out alike. All 27 locales carry the new strings, and
the wiki describes the link and the tools.
This commit is contained in:
Maurice
2026-10-20 13:56:42 +02:00
parent 65fe8cd6e5
commit f833a05461
106 changed files with 3661 additions and 22 deletions
@@ -0,0 +1,29 @@
import { EntityRepositoryType, type Opt, PrimaryKeyProp, type Ref, defineEntity, p } from '@mikro-orm/core';
import { TourPackingLinksRepository } from '../repositories/TourPackingLinks.repository';
import { DbTimestampType } from '../types';
import { Tours } from './Tours.entity';
import { Users } from './Users.entity';
export class TourPackingLinks {
[EntityRepositoryType]?: TourPackingLinksRepository;
[PrimaryKeyProp]?: 'place';
place?: Ref<Tours> | null;
place_id?: number | null;
category?: string | null;
linked_by?: number | null;
linked_at!: string & Opt;
linkedByRef?: Ref<Users> | null;
}
export const TourPackingLinksSchema = defineEntity({
class: TourPackingLinks,
repository: () => TourPackingLinksRepository,
properties: {
place: () => p.oneToOne(Tours).primary().ref().name('place_id').deleteRule('cascade').nullable().hidden(),
place_id: p.integer().nullable().persist(false),
category: p.text().nullable(),
linked_by: p.integer().nullable().persist(false).index('idx_tour_packing_links_linked_by'),
linked_at: p.type(DbTimestampType).defaultRaw(`CURRENT_TIMESTAMP`),
linkedByRef: () => p.manyToOne(Users).ref().joinColumn('linked_by').nullable().hidden().index('idx_tour_packing_links_linked_by'),
},
});
+3
View File
@@ -6,6 +6,7 @@ import { TourActivities } from './TourActivities.entity';
import { TourActivityExclusions } from './TourActivityExclusions.entity';
import { TourChangeSteps } from './TourChangeSteps.entity';
import { TourObstacleReviews } from './TourObstacleReviews.entity';
import { TourPackingLinks } from './TourPackingLinks.entity';
import { TourSources } from './TourSources.entity';
import { TourTypes } from './TourTypes.entity';
import { TourWaypoints } from './TourWaypoints.entity';
@@ -56,6 +57,7 @@ export class Tours {
tour_activity_exclusions_collection = new Collection<TourActivityExclusions>(this);
tour_change_steps_collection = new Collection<TourChangeSteps>(this);
tour_obstacle_reviews_collection = new Collection<TourObstacleReviews>(this);
tour_packing_links: Ref<TourPackingLinks> | null = null;
tour_sources: Ref<TourSources> | null = null;
tour_waypoints_collection = new Collection<TourWaypoints>(this);
}
@@ -192,6 +194,7 @@ export const ToursSchema = defineEntity({
tour_activity_exclusions_collection: () => p.oneToMany(TourActivityExclusions).mappedBy('place').hidden(),
tour_change_steps_collection: () => p.oneToMany(TourChangeSteps).mappedBy('place').hidden(),
tour_obstacle_reviews_collection: () => p.oneToMany(TourObstacleReviews).mappedBy('place').hidden(),
tour_packing_links: () => p.oneToOne(TourPackingLinks).ref().mappedBy('place').hidden(),
tour_sources: () => p.oneToOne(TourSources).ref().mappedBy('place').hidden(),
tour_waypoints_collection: () => p.oneToMany(TourWaypoints).mappedBy('place').hidden(),
},
+3
View File
@@ -54,6 +54,7 @@ import { TodoCategoryAssignees } from './TodoCategoryAssignees.entity';
import { TodoItems } from './TodoItems.entity';
import { TourActivities } from './TourActivities.entity';
import { TourActivityExclusions } from './TourActivityExclusions.entity';
import { TourPackingLinks } from './TourPackingLinks.entity';
import { TourSources } from './TourSources.entity';
import { TrekPhotos } from './TrekPhotos.entity';
import { TripAlbumLinks } from './TripAlbumLinks.entity';
@@ -184,6 +185,7 @@ export class Users {
todo_items_collection = new Collection<TodoItems>(this);
tour_activities_collection = new Collection<TourActivities>(this);
tour_activity_exclusions_collection = new Collection<TourActivityExclusions>(this);
tour_packing_links_collection = new Collection<TourPackingLinks>(this);
tour_sources_collection = new Collection<TourSources>(this);
trek_photos_collection = new Collection<TrekPhotos>(this);
trip_album_links_collection = new Collection<TripAlbumLinks>(this);
@@ -332,6 +334,7 @@ export const UsersSchema = defineEntity({
todo_items_collection: () => p.oneToMany(TodoItems).mappedBy('assignedUser').hidden(),
tour_activities_collection: () => p.oneToMany(TourActivities).mappedBy('assignedByRef').hidden(),
tour_activity_exclusions_collection: () => p.oneToMany(TourActivityExclusions).mappedBy('user').hidden(),
tour_packing_links_collection: () => p.oneToMany(TourPackingLinks).mappedBy('linkedByRef').hidden(),
tour_sources_collection: () => p.oneToMany(TourSources).mappedBy('importedByRef').hidden(),
trek_photos_collection: () => p.oneToMany(TrekPhotos).mappedBy('owner').hidden(),
trip_album_links_collection: () => p.oneToMany(TripAlbumLinks).mappedBy('user').hidden(),
+2
View File
@@ -112,6 +112,7 @@ import { TourActivitiesSchema } from './TourActivities.entity';
import { TourActivityExclusionsSchema } from './TourActivityExclusions.entity';
import { TourChangeStepsSchema } from './TourChangeSteps.entity';
import { TourObstacleReviewsSchema } from './TourObstacleReviews.entity';
import { TourPackingLinksSchema } from './TourPackingLinks.entity';
import { TourSourcesSchema } from './TourSources.entity';
import { TourStationVisitsSchema } from './TourStationVisits.entity';
import { TourTypesSchema } from './TourTypes.entity';
@@ -261,6 +262,7 @@ export const ALL_ENTITIES: readonly EntitySchema[] = [
TourActivityExclusionsSchema,
TourChangeStepsSchema,
TourObstacleReviewsSchema,
TourPackingLinksSchema,
TourSourcesSchema,
TourStationVisitsSchema,
TourTypesSchema,
@@ -0,0 +1,10 @@
// Generated by scripts/generate-db-types.ts from the migrated schema. Do not edit by hand:
// change the migration, then run `npm run gen:db-types`.
import type { InsertOptional } from './columns';
export interface TourPackingLinksTable {
place_id: InsertOptional<number>;
category: InsertOptional<string | null>;
linked_by: InsertOptional<number | null>;
linked_at: InsertOptional<string>;
}
+2
View File
@@ -118,6 +118,7 @@ import type { TourActivitiesTable } from './TourActivities.table';
import type { TourActivityExclusionsTable } from './TourActivityExclusions.table';
import type { TourChangeStepsTable } from './TourChangeSteps.table';
import type { TourObstacleReviewsTable } from './TourObstacleReviews.table';
import type { TourPackingLinksTable } from './TourPackingLinks.table';
import type { TourSourcesTable } from './TourSources.table';
import type { TourStationVisitsTable } from './TourStationVisits.table';
import type { TourTypesTable } from './TourTypes.table';
@@ -273,6 +274,7 @@ export interface DB {
tour_activity_exclusions: TourActivityExclusionsTable;
tour_change_steps: TourChangeStepsTable;
tour_obstacle_reviews: TourObstacleReviewsTable;
tour_packing_links: TourPackingLinksTable;
tour_sources: TourSourcesTable;
tour_station_visits: TourStationVisitsTable;
tour_types: TourTypesTable;
@@ -0,0 +1,25 @@
import { Migration } from '@mikro-orm/migrations';
/**
* P2D-XD-01: a tour points at the packing list of its trip, as a whole or at
* one of its categories. The row only names what it points at: `category` is
* NULL for the whole list, otherwise the category as its items carry it. The
* items stay Packing's, so nothing here copies, owns or deletes one, and
* removing the row leaves the list as it was. One link per tour, gone with
* the tour; `linked_by` turns unknown when that account goes.
*/
export class Migration20200101046110_a_tour_points_at_its_packing_list extends Migration {
override name = 'Migration20200101046110_a_tour_points_at_its_packing_list';
override up(): void {
this.addSql(`
CREATE TABLE IF NOT EXISTS tour_packing_links (
place_id INTEGER PRIMARY KEY REFERENCES tours(place_id) ON DELETE CASCADE,
category TEXT,
linked_by INTEGER REFERENCES users(id) ON DELETE SET NULL,
linked_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP
)
`);
this.addSql('CREATE INDEX IF NOT EXISTS idx_tour_packing_links_linked_by ON tour_packing_links(linked_by)');
}
}
@@ -0,0 +1,55 @@
import { currentTimestampKysely } from '../dialect/kysely-functions';
import type { TourPackingLinks } from '../entities/TourPackingLinks.entity';
import type { DB } from '../kysely/db';
import { TrekRepository } from './_shared/trek-repository';
type LinksDB = Pick<DB, 'tour_packing_links'>;
/** What a tour points at in its trip's packing list: null for the whole list, otherwise one category. */
interface TourPackingLinkRow {
category: string | null;
linked_at: string;
}
/**
* `tour_packing_links` (P2D-XD-01): the packing list, or the category of it,
* a tour points at. One row per tour, gone with the tour. It names what it
* points at and nothing else, so no statement here reaches a packing item.
*/
export class TourPackingLinksRepository extends TrekRepository<TourPackingLinks> {
private db() {
return this.kysely<LinksDB>();
}
/** The tour's link; undefined while it points at nothing. */
async findForTour(place_id: number): Promise<TourPackingLinkRow | undefined> {
return await this.db()
.selectFrom('tour_packing_links')
.select(['category', 'linked_at'])
.where('place_id', '=', place_id)
.executeTakeFirst();
}
/** Points the tour at the list or a category, replacing what it pointed at before; the time is the new link's. */
async put(place_id: number, category: string | null, linked_by: number): Promise<void> {
const platform = this.getEntityManager().getPlatform();
await this.db()
.insertInto('tour_packing_links')
.values({ place_id, category, linked_by })
.onConflict((oc) =>
oc.column('place_id').doUpdateSet((eb) => ({
category: eb.ref('excluded.category'),
linked_by: eb.ref('excluded.linked_by'),
// The clock in the spelling of the live database: CURRENT_TIMESTAMP is no function call.
linked_at: currentTimestampKysely(platform),
})),
)
.execute();
}
/** Lets go of what the tour points at; false when it pointed at nothing. */
async remove(place_id: number): Promise<boolean> {
const result = await this.db().deleteFrom('tour_packing_links').where('place_id', '=', place_id).executeTakeFirst();
return Number(result.numDeletedRows ?? 0) > 0;
}
}
@@ -215,6 +215,7 @@ type ToursKyselyDB = Pick<
| 'tour_sources'
| 'days'
| 'tour_obstacle_reviews'
| 'tour_packing_links'
| 'trips'
>;
@@ -569,6 +570,35 @@ export class ToursRepository extends TrekRepository<Tours> {
.execute();
}
/**
* P2D-XD-01: the packing list or category a copied tour pointed at, onto its
* copy in the copied trip, whose packing list is copied too. Nothing for a
* tour that pointed at nothing.
*/
async copyPackingLink(source_place_id: number, place_id: number): Promise<void> {
await this.db()
.insertInto('tour_packing_links')
.columns(['place_id', 'category', 'linked_by', 'linked_at'])
.expression((eb) =>
eb
.selectFrom('tour_packing_links')
.select((inner) => [inner.val(place_id).as('place_id'), 'category', 'linked_by', 'linked_at'])
.where('place_id', '=', source_place_id),
)
.execute();
}
/**
* What a copied trip's tour keeps besides its facet and its points: its
* import record, its obstacle decisions and its packing link, onto its copy.
* Called inside the trip copy's transaction.
*/
async copyTourRelations(source_place_id: number, place_id: number): Promise<void> {
await this.copySource(source_place_id, place_id);
await this.copyObstacleReviews(source_place_id, place_id);
await this.copyPackingLink(source_place_id, place_id);
}
/** The days every tour of a trip sits on, each tour and day once, in day order, with the stage a day holds (MDT-02). */
async listTourDays(trip_id: number): Promise<TourDayRow[]> {
return await this.db()