mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-12-03 17:41:51 +00:00
2449616ee9
A hut-to-hut hike or a paddle trip over several days is now planned in the Tours planner as one tour: the whole route is planned as before, and stops along it are marked as stage ends (MDT-01). The stages are read off that one route in its order, never kept as copies, so a change inside a stage changes the whole tour and every figure on it. - A Day tour / Multi-day tour switch beside the tour type; a stop's menu ends a stage there or lets it go on. Back to a day tour removes every stage end after a confirmation, as one step undo brings back. - The list of points is headed per stage with its distance and moving time; a stop that ends a stage carries a moon at its number, on the map too. - The overview lists the stages from stop to stop with distance, climb, descent and time (hiking rule per stage, paddle estimate per stage, the router's time shared by distance otherwise), marks where each ends across the elevation profile, and a stage of more than a day on the move warns. - A stage end a change cannot keep (its stop removed, moved to an end or made a shaping point) is dropped and said so, with undo, never moved to another point. - A multi-day tour may take a day a stage, so its time limit grows with its stages; the tour keeps its one type, portages included. - The list and the MCP tools show the stage count and where stages end. Stage ends are a flag on the waypoint (migration 046000); a tour without one is a day tour, as every tour saved before.
89 lines
3.4 KiB
TypeScript
89 lines
3.4 KiB
TypeScript
import { TourActivities } from '../../../src/db/entities/TourActivities.entity';
|
|
import { TourStationVisits, type TTourStationVisitsStatus } from '../../../src/db/entities/TourStationVisits.entity';
|
|
import { TourWaypoints, type TTourWaypointsImportance } from '../../../src/db/entities/TourWaypoints.entity';
|
|
import { Tours } from '../../../src/db/entities/Tours.entity';
|
|
import type { FactoryOrm } from './context';
|
|
import { createRow, findRow, insertRow, insertRows } from './rows';
|
|
import type { EntityData, EntityDTO } from '@mikro-orm/core';
|
|
|
|
export type TourRow = EntityDTO<Tours>;
|
|
|
|
/**
|
|
* Turns the place into a tour. A tour is keyed by its place, so it has no id
|
|
* of its own; its type defaults to 'hike', the one the tours migration seeds.
|
|
*/
|
|
export async function makeTour(orm: FactoryOrm, placeId: number, overrides: EntityData<Tours> = {}): Promise<TourRow> {
|
|
await insertRow(orm, Tours, { place: placeId, tourTypeRef: 'hike' }, overrides);
|
|
const tour = await findRow(orm, Tours, { place: placeId });
|
|
if (!tour) throw new Error(`makeTour: no tour for place ${placeId} after its insert`);
|
|
return tour;
|
|
}
|
|
|
|
type WaypointRole = 'start' | 'via' | 'end';
|
|
|
|
/** A city walk station's columns (CW-01 to CW-04), a shaping point's and a stage end's flags and the place a point stands for. */
|
|
interface StationColumns {
|
|
station_key?: string | null;
|
|
name?: string | null;
|
|
stay_minutes?: number | null;
|
|
importance?: TTourWaypointsImportance | null;
|
|
/** 1 for a protected station. */
|
|
protected?: number;
|
|
opening_hours?: string | null;
|
|
/** 1 for a shaping point. */
|
|
shaping?: number;
|
|
/** MDT-01: 1 for a stop that ends a stage of a multi-day tour. */
|
|
stage_end?: number;
|
|
/** The id of the place of the trip the point stands for. */
|
|
linkedPlace?: number | null;
|
|
/** The leg to the next point as a fixed line, as its JSON column stores it. */
|
|
fixed_leg?: string | null;
|
|
}
|
|
|
|
/**
|
|
* The tour's waypoints, in the order given and numbered from 0. Without a
|
|
* role the first is the start, the last the end and the rest are vias. A
|
|
* point may carry a station's columns; those it leaves out take their defaults.
|
|
*/
|
|
export async function addTourWaypoints(
|
|
orm: FactoryOrm,
|
|
placeId: number,
|
|
points: Array<{ lat: number; lng: number; role?: WaypointRole } & StationColumns>,
|
|
): Promise<void> {
|
|
const roleAt = (i: number): WaypointRole => (i === 0 ? 'start' : i === points.length - 1 ? 'end' : 'via');
|
|
await insertRows(
|
|
orm,
|
|
TourWaypoints,
|
|
points.map(({ lat, lng, role, ...station }, sequence) => ({
|
|
...station,
|
|
place: placeId,
|
|
lat,
|
|
lng,
|
|
role: role ?? roleAt(sequence),
|
|
sequence,
|
|
})),
|
|
);
|
|
}
|
|
|
|
/** CW-03: a station of a city walk visited or skipped on the day the assignment puts the walk on. */
|
|
export async function markStationVisit(
|
|
orm: FactoryOrm,
|
|
assignmentId: number,
|
|
stationKey: string,
|
|
status: TTourStationVisitsStatus,
|
|
): Promise<void> {
|
|
await insertRow(orm, TourStationVisits, { assignment: assignmentId, station_key: stationKey, status });
|
|
}
|
|
|
|
type TourActivityRow = EntityDTO<TourActivities>;
|
|
|
|
/** ACT-01: the recording `trackPlaceId` assigned to the tour, on no day unless `assignment` names one. */
|
|
export function makeTourActivity(
|
|
orm: FactoryOrm,
|
|
placeId: number,
|
|
trackPlaceId: number,
|
|
overrides: EntityData<TourActivities> = {},
|
|
): Promise<TourActivityRow> {
|
|
return createRow(orm, TourActivities, { place: placeId, trackPlace: trackPlaceId }, overrides);
|
|
}
|