mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-30 08:30:05 +00:00
e5f01e570a
Marking a stop of a city walk visited or skipped answered with a server error every time: the write that keeps a changed status stamped its time as a function call, which neither SQLite nor Postgres takes. It now uses the clock the database itself spells, so a stop checked off, skipped or taken back stays that way and the day plan of everyone on the trip follows. The Save button of a stop's dialog in the planner did nothing, because it sat outside the dialog's form. It saves the name, stay, importance and protection again. A walk saved with two points that carry one key, as a loop back to the start does, keeps that key on the first point and gives the other one of its own, so checking one off never marks both. A walk put on one day twice is read for an assistant from its first assignment. The server tests cover the visits from the repository to the routes: per day, through a moved and a removed assignment, a copy of the walk and a copied trip without visits, a removed stop taking its visits along, and the refusals for another trip, a stop the walk does not have, a member who may not edit days and an unknown key or body. The MCP progress of a walk, the station fields and counts of the tour list, and the contracts in shared are tested too; the existing tests expect the keys every saved point now carries, the station count of a list row and the new entity. The client tests cover the stop dialog and its pills, the walk themes and categories of the search along a tour, the stop menu of the waypoint list, the walk's timing, routing and type choice, and answer the trip planner's read of the visits in the tests instead of leaving it unanswered.
72 lines
2.7 KiB
TypeScript
72 lines
2.7 KiB
TypeScript
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 { 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 flag 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;
|
|
/** The id of the place of the trip the point stands for. */
|
|
linkedPlace?: number | 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 });
|
|
}
|