Tours: copy a planned tour's import link in the repository, and teach the tests the new columns

This commit is contained in:
Maurice
2026-10-15 18:38:44 +02:00
parent f1c437b8b8
commit 11f23997e8
6 changed files with 48 additions and 8 deletions
+14 -3
View File
@@ -220,12 +220,23 @@ export class ToursRepository extends TrekRepository<Tours> {
/**
* TO8 — a copied tour keeps every column, `created_at` included, so the
* copy lists its tours in the source's order.
* copy lists its tours in the source's order. A tour planned from an import
* points at the copied import (`copiedPlaceIds` maps source to copy), never
* back into the source trip.
*/
async insertCopy(place_id: number, row: Omit<TourRow, 'place_id'>): Promise<void> {
async insertCopy(
place_id: number,
row: Omit<TourRow, 'place_id'>,
copiedPlaceIds: ReadonlyMap<number, number>,
): Promise<void> {
const derivedFrom = row.derived_from_place_id;
await this.db()
.insertInto('tours')
.values({ ...row, place_id })
.values({
...row,
place_id,
derived_from_place_id: derivedFrom === null ? null : (copiedPlaceIds.get(derivedFrom) ?? null),
})
.execute();
}
+1 -4
View File
@@ -743,10 +743,7 @@ export class TripsService {
for (const { place_id, ...tour } of oldTours) {
const newPlaceId = placeMap.get(place_id);
if (!newPlaceId) continue;
// A tour planned from an import points at the copied import, never back into the source trip.
const derivedFrom =
tour.derived_from_place_id === null ? null : (placeMap.get(tour.derived_from_place_id) ?? null);
await this.toursRepo.insertCopy(newPlaceId, { ...tour, derived_from_place_id: derivedFrom });
await this.toursRepo.insertCopy(newPlaceId, tour, placeMap);
copiedTours.add(place_id);
}