mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-10-21 14:36:31 +00:00
d0cc6fc2f4
A planned tour can now be given the track it was actually done with. In the tour's detail, "Add actual track" opens a dialog that asks for the day the tour was done on (or none) and a recording of the trip: an import nobody planned over, or a new one through the existing GPX import, its preview preset to the tour's type. What the choice measures is shown before anything is written, and only "Link" writes. The linked track keeps its own name and source; the detail shows its distance, heights, profile and, only where the file carried time stamps, the time it took, marked as actual values next to the untouched plan. A track can be changed or unlinked again. Server: a tour_activities table points a tour's execution (a day assignment, or none) at a recording of the same trip, and the tours GPX import keeps the first and last time of a track whose every point carries one. The values are read from the recording's own line on every read, so a changed recording updates them while the plan's line, measures and revision stay as they were. Every check runs inside the write: the recording must be an import of this trip not planned over, documenting no other tour; the day must be one of this tour; a refusal names its reason and changes nothing. PUT and DELETE /api/trips/:tripId/tours/:placeId/activities answer the detail, which now carries the actual tracks; the list names them per tour and per recording. MCP: assign_tour_track and unassign_tour_track over the same service and checks, get_tour_plan reads the values without the line. A recording linked as a tour's actual track is no longer counted as a tour of its own in the trip's tour summary, and the GPX preview imports a city walk as one instead of as a hike.
63 lines
2.7 KiB
TypeScript
63 lines
2.7 KiB
TypeScript
import { TourActivities } from '../../src/db/entities/TourActivities.entity';
|
|
import { TourStationVisits } from '../../src/db/entities/TourStationVisits.entity';
|
|
import { TourTypes } from '../../src/db/entities/TourTypes.entity';
|
|
import { TourWaypoints } from '../../src/db/entities/TourWaypoints.entity';
|
|
import { Tours } from '../../src/db/entities/Tours.entity';
|
|
import type { TourActivitiesRepository } from '../../src/db/repositories/TourActivities.repository';
|
|
import type { TourStationVisitsRepository } from '../../src/db/repositories/TourStationVisits.repository';
|
|
import type { TourTypesRepository } from '../../src/db/repositories/TourTypes.repository';
|
|
import type { TourWaypointsRepository } from '../../src/db/repositories/TourWaypoints.repository';
|
|
import type { ToursRepository } from '../../src/db/repositories/Tours.repository';
|
|
import { sharedTestOrm } from './test-uow';
|
|
|
|
import type Database from 'better-sqlite3';
|
|
|
|
/**
|
|
* Tours test-only repository factories, bound to a suite's own better-sqlite3
|
|
* handle through the same memoised `sharedTestOrm` `test-uow.ts` exports, so
|
|
* a repository built here and a `UnitOfWork` from `createTestUnitOfWork`
|
|
* resolve the same `EntityManager` (the `todo-repos.ts` precedent).
|
|
*/
|
|
export function createTestToursRepo(db: Database.Database): Promise<ToursRepository> {
|
|
return sharedTestOrm(db).then((t) => t.repo(Tours));
|
|
}
|
|
|
|
export function createTestTourTypesRepo(db: Database.Database): Promise<TourTypesRepository> {
|
|
return sharedTestOrm(db).then((t) => t.repo(TourTypes));
|
|
}
|
|
|
|
export function createTestTourWaypointsRepo(db: Database.Database): Promise<TourWaypointsRepository> {
|
|
return sharedTestOrm(db).then((t) => t.repo(TourWaypoints));
|
|
}
|
|
|
|
export function createTestTourStationVisitsRepo(db: Database.Database): Promise<TourStationVisitsRepository> {
|
|
return sharedTestOrm(db).then((t) => t.repo(TourStationVisits));
|
|
}
|
|
|
|
export function createTestTourActivitiesRepo(db: Database.Database): Promise<TourActivitiesRepository> {
|
|
return sharedTestOrm(db).then((t) => t.repo(TourActivities));
|
|
}
|
|
|
|
/** A `tours` row for an existing place, with the defaults a GPX import writes. */
|
|
export function createTour(
|
|
db: Database.Database,
|
|
placeId: number,
|
|
overrides: Partial<{
|
|
distance: number | null;
|
|
match_confidence: number | null;
|
|
max_hiking_difficulty: number;
|
|
created_at: string;
|
|
}> = {},
|
|
): void {
|
|
db.prepare(
|
|
`INSERT INTO tours (place_id, tour_type, distance, match_confidence, max_hiking_difficulty, created_at)
|
|
VALUES (?, 'hike', ?, ?, ?, COALESCE(?, CURRENT_TIMESTAMP))`,
|
|
).run(
|
|
placeId,
|
|
overrides.distance ?? null,
|
|
overrides.match_confidence ?? null,
|
|
overrides.max_hiking_difficulty ?? 2,
|
|
overrides.created_at ?? null,
|
|
);
|
|
}
|