mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-25 22:27:32 +00:00
Tours: copy a planned tour's import link in the repository, and teach the tests the new columns
This commit is contained in:
@@ -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();
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user