mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-22 13:10:29 +00:00
f833a05461
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.
56 lines
2.2 KiB
TypeScript
56 lines
2.2 KiB
TypeScript
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;
|
|
}
|
|
}
|