fix(tours): a recorded track is neither turned round nor closed by update_tour

A GPX import keeps no points of its own, and the tour read makes up a start
and an end from its line. update_tour with reshape turned or closed those two
made up points, so the recorded line was replaced by a router line between its
ends. A reshape of a tour without points of its own is now refused with the
recorded track wording, before anything is planned or saved.
This commit is contained in:
Maurice
2026-10-24 01:53:51 +00:00
parent 508e17bc11
commit 1a941a6f1d
2 changed files with 34 additions and 6 deletions
+8 -5
View File
@@ -137,11 +137,14 @@ function repointingRefusal(saved: readonly TourWaypoint[], points: readonly Hike
return null;
}
/** The change with the saved points reshaped as its new points, or refused with why (a hike only). */
function withReshape(request: TourUpdateRequest, saved: readonly TourWaypoint[], type: string): TourUpdateRequest {
/**
* The change with the saved points reshaped as its new points, or refused with why (a hike only). A
* recorded track has no points of its own to turn: the two its read gives are made up from its line's ends.
*/
function withReshape(request: TourUpdateRequest, { tour, waypoints }: TourDetailResponse): TourUpdateRequest {
const { reshape, ...rest } = request;
if (!reshape || type !== 'hike') return rest;
const reshaped = reshapedHikePoints(saved, reshape);
if (!reshape || tour.tour_type !== 'hike') return rest;
const reshaped = reshapedHikePoints(tour.has_waypoints === true ? waypoints : [], reshape);
if ('refused' in reshaped) throw badRequest(reshaped.refused);
return { ...rest, waypoints: reshaped.points };
}
@@ -395,7 +398,7 @@ export class HikePlanService {
const { placeId } = asked;
const saved = await this.tours.getTour(String(tripId), String(placeId));
// PR1-01, PR1-02: a reshape is the saved points turned or closed, then planned as new points are.
const request = asked.reshape ? withReshape(asked, saved.waypoints, saved.tour.tour_type) : asked;
const request = asked.reshape ? withReshape(asked, saved) : asked;
const { tour } = saved;
if (tour.tour_type !== 'hike') {
throw badRequest(