fix(days): a day without a date keeps no date when it is moved, so it can go to the front of a dated trip

Reordering handed out the dates by position, so moving a day added without a
date to the front gave it the first date and took the date of the last dated
day. The undated row stayed at the end and the move looked like it did
nothing, by drag and by the arrows alike. The dates now go to the dated days
only, in their new order; the rule lives in shared so the server, the
planner's optimistic list and the MCP tool apply the same one.
This commit is contained in:
Maurice
2026-10-10 17:08:28 +02:00
parent d496dd5d30
commit d2e044869a
7 changed files with 106 additions and 11 deletions
+1 -1
View File
@@ -157,7 +157,7 @@ export class DaysMcp {
@Tool({
name: 'reorder_days',
description:
'Reorder the days of a trip by listing every one of its day IDs in the desired order. This moves whole days of the itinerary; to move places around inside a single day use reorder_day_assignments instead. Each day keeps its places, notes, stays and bookings, and on a dated trip the calendar dates stay pinned to their slots, so the content moves across the dates.',
'Reorder the days of a trip by listing every one of its day IDs in the desired order. This moves whole days of the itinerary; to move places around inside a single day use reorder_day_assignments instead. Each day keeps its places, notes, stays and bookings, and on a dated trip the calendar dates stay pinned to their slots, so the content moves across the dates; a day without a date keeps none wherever it is moved.',
inputSchema: {
tripId: idSchema,
orderedIds: dayReorderRequestSchema.shape.orderedIds
+5 -8
View File
@@ -28,7 +28,7 @@ import { QueryHelpersService } from '../query-helpers/query-helpers.service';
import { RealtimeService } from '../realtime/realtime.service';
import { InjectRepository } from '@mikro-orm/nestjs';
import { Injectable } from '@nestjs/common';
import { addIsoDays, MAX_TRIP_DAYS, planDatedAppend } from '@trek/shared';
import { addIsoDays, MAX_TRIP_DAYS, planDatedAppend, reorderedDayDates } from '@trek/shared';
import type { RoadtripDayBoundary, TrekWsPayload, TrekWsTripEventName } from '@trek/shared';
type Trip = TripAccess;
@@ -594,12 +594,9 @@ export class DaysService {
}
const oldDateById = new Map(rows.map((r) => [r.id, r.date]));
// Dates stay pinned to slots: position i keeps the i-th date (ascending).
const sortedDates = rows
.map((r) => r.date)
.filter((d): d is string => !!d)
.sort((a, b) => (a < b ? -1 : a > b ? 1 : 0));
const isDated = sortedDates.length > 0;
// Dates stay pinned to the slots of the dated days; a day without a date keeps none.
const newDates = reorderedDayDates(rows, orderedIds);
const isDated = rows.some((r) => !!r.date);
await this.uow.transactional(async () => {
// Two-phase renumber to dodge UNIQUE(trip_id, day_number) collisions —
@@ -610,7 +607,7 @@ export class DaysService {
}
const newDateById = new Map<number, string | null>();
for (const [i, id] of orderedIds.entries()) {
const date = isDated ? (sortedDates[i] ?? null) : null;
const date = newDates.get(id) ?? null;
await this.daysRepo.setDayNumberAndDate(id, i + 1, date);
newDateById.set(id, date);
}