mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-27 15:17:30 +00:00
fix(tours): check a city walk's stops off and save a stop from its dialog, with the walk under test (CW-01 to CW-05, CW-09)
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.
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
import { currentTimestampKysely } from '../dialect/kysely-functions';
|
||||
import type { TourStationVisits, TTourStationVisitsStatus } from '../entities/TourStationVisits.entity';
|
||||
import type { DB } from '../kysely/db';
|
||||
import { TrekRepository } from './_shared/trek-repository';
|
||||
@@ -40,7 +41,10 @@ export class TourStationVisitsRepository extends TrekRepository<TourStationVisit
|
||||
.executeTakeFirst();
|
||||
}
|
||||
|
||||
/** The assignment that puts this place on this day of this trip; undefined where there is none. */
|
||||
/**
|
||||
* The assignment that puts this place on this day of this trip; undefined where there is none.
|
||||
* A walk put on one day twice answers its first assignment, the one with the lowest id.
|
||||
*/
|
||||
async assignmentOnDay(trip_id: number, place_id: number, day_id: number): Promise<number | undefined> {
|
||||
const row = await this.db()
|
||||
.selectFrom('day_assignments as da')
|
||||
@@ -49,6 +53,7 @@ export class TourStationVisitsRepository extends TrekRepository<TourStationVisit
|
||||
.where('da.place_id', '=', place_id)
|
||||
.where('da.day_id', '=', day_id)
|
||||
.where('d.trip_id', '=', trip_id)
|
||||
.orderBy('da.id', 'asc')
|
||||
.executeTakeFirst();
|
||||
return row?.id;
|
||||
}
|
||||
@@ -78,13 +83,15 @@ export class TourStationVisitsRepository extends TrekRepository<TourStationVisit
|
||||
|
||||
/** Marks a station visited or skipped on that day, replacing what it was. */
|
||||
async set(assignment_id: number, station_key: string, status: TTourStationVisitsStatus): Promise<void> {
|
||||
const platform = this.getEntityManager().getPlatform();
|
||||
await this.db()
|
||||
.insertInto('tour_station_visits')
|
||||
.values({ assignment_id, station_key, status })
|
||||
.onConflict((oc) =>
|
||||
oc.columns(['assignment_id', 'station_key']).doUpdateSet((eb) => ({
|
||||
status: eb.ref('excluded.status'),
|
||||
updated_at: eb.fn<string>('CURRENT_TIMESTAMP', []),
|
||||
// The clock in the spelling of the live database: CURRENT_TIMESTAMP is no function call.
|
||||
updated_at: currentTimestampKysely(platform),
|
||||
})),
|
||||
)
|
||||
.execute();
|
||||
|
||||
@@ -800,6 +800,6 @@ function toListRow<
|
||||
planned: Number(r.planned),
|
||||
has_waypoints: Number(r.has_waypoints),
|
||||
has_recorded_track: Number(r.has_recorded_track),
|
||||
station_count: Number(r.station_count ?? 0),
|
||||
station_count: Number(r.station_count),
|
||||
};
|
||||
}
|
||||
|
||||
@@ -81,10 +81,17 @@ function hikingFields(input: TourCreateRequest): string | null {
|
||||
|
||||
/**
|
||||
* CW-03: every point with its key, kept from the write where it came with one,
|
||||
* so the visits of a city walk's stations outlast a reorder or a new point.
|
||||
* so the visits of a city walk's stations outlast a reorder or a new point. A
|
||||
* key sent twice stays with its first point; a later one gets a fresh key, so
|
||||
* checking one station off never marks another.
|
||||
*/
|
||||
function keyedWaypoints(waypoints: TourWaypoint[]): TourWaypoint[] {
|
||||
return waypoints.map((point) => (point.key ? point : { ...point, key: randomUUID() }));
|
||||
function keyedWaypoints(waypoints: TourWaypoint[]): Array<TourWaypoint & { key: string }> {
|
||||
const taken = new Set<string>();
|
||||
return waypoints.map((point) => {
|
||||
const key = point.key && !taken.has(point.key) ? point.key : randomUUID();
|
||||
taken.add(key);
|
||||
return { ...point, key };
|
||||
});
|
||||
}
|
||||
|
||||
@Injectable()
|
||||
@@ -590,7 +597,7 @@ export class ToursService {
|
||||
const waypoints = keyedWaypoints(await this.linkedWaypoints(tid, input.waypoints));
|
||||
await this.waypointsRepo.insertForPlace(pid, waypoints);
|
||||
// CW-03: a station that is gone takes its visits with it; a tour that is no city walk keeps none.
|
||||
const stations = input.tour_type === 'walk' ? waypoints.flatMap((point) => (point.key ? [point.key] : [])) : [];
|
||||
const stations = input.tour_type === 'walk' ? waypoints.map((point) => point.key) : [];
|
||||
await this.visitsRepo.dropStationsNotIn(pid, stations);
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user