fix(tours): one tour type catalogue, and no column nothing writes

tour_types now holds every key the shared contract accepts, all but hike
disabled, and create and edit turn a disabled type away with a 400 instead
of failing on the foreign key. tours.tour_group_id is dropped: nothing ever
wrote or read it. difficulty and wanderer_ref stay for the Wanderer import.
This commit is contained in:
Maurice
2026-10-07 20:54:10 +02:00
parent f64f9e58de
commit f7edd849ab
29 changed files with 182 additions and 50 deletions
-2
View File
@@ -17,7 +17,6 @@ export class Tours {
difficulty?: string | null;
wanderer_ref?: string | null;
match_confidence?: number | null;
tour_group_id?: number | null;
created_at?: string | null;
max_hiking_difficulty: number & Opt = 2;
tourTypeRef!: Ref<TourTypes>;
@@ -38,7 +37,6 @@ export const ToursSchema = defineEntity({
difficulty: p.text().nullable(),
wanderer_ref: p.text().nullable(),
match_confidence: p.double().nullable(),
tour_group_id: p.integer().nullable(),
created_at: p.text().nullable().defaultRaw(`CURRENT_TIMESTAMP`),
max_hiking_difficulty: p.integer().default(2),
tourTypeRef: () => p.manyToOne(TourTypes).ref().joinColumn('tour_type').hidden().index('idx_tours_tour_type'),
@@ -0,0 +1,33 @@
import { Migration } from '@mikro-orm/migrations';
import { columnNames } from '../migration-utils';
/**
* `tour_types` holds every key the shared `tourTypeKeySchema` accepts. Only
* `hike` was seeded, so a tour of any other type the contract allows failed
* on the foreign key with a 500 instead of a clean refusal. The six others
* are written disabled: the planner only offers `hike` today, and the
* service turns a disabled type away with a 400.
*
* `tours.tour_group_id` goes. Nothing ever wrote or read it, and a column
* nothing writes lets every copy and export carry a meaning nobody defined.
* `difficulty` and `wanderer_ref` stay: the Wanderer import fills them.
*/
export class Migration20200101042300_every_tour_type_the_contract_names extends Migration {
override name = 'Migration20200101042300_every_tour_type_the_contract_names';
override async up(): Promise<void> {
this.addSql(`
INSERT OR IGNORE INTO tour_types (key, label_key, icon, color, routing_profile, is_sport, enabled, sort_order) VALUES
('bike', 'tourTypes.bike', 'Bike', '#2563eb', 'bicycle', 1, 0, 1),
('run', 'tourTypes.run', 'Footprints', '#dc2626', 'pedestrian', 1, 0, 2),
('ski', 'tourTypes.ski', 'MountainSnow', '#0891b2', NULL, 1, 0, 3),
('kayak', 'tourTypes.kayak', 'Sailboat', '#0d9488', NULL, 1, 0, 4),
('walk', 'tourTypes.walk', 'Landmark', '#9333ea', 'pedestrian', 0, 0, 5),
('food', 'tourTypes.food', 'UtensilsCrossed', '#ea580c', 'pedestrian', 0, 0, 6)
`);
if ((await columnNames(this, 'tours')).has('tour_group_id')) {
this.addSql('ALTER TABLE tours DROP COLUMN tour_group_id');
}
}
}
@@ -2,8 +2,14 @@ import type { TourTypes } from '../entities/TourTypes.entity';
import { TrekRepository } from './_shared/trek-repository';
/**
* `tour_types` — the controlled vocabulary `tours.tour_type` points at. Only
* `hike` exists, written by the migration that creates the table; nothing
* reads the catalogue yet, so this repository has no methods of its own.
* `tour_types` — the controlled vocabulary `tours.tour_type` points at, one
* row per key of the shared `tourTypeKeySchema`. The migrations write it;
* `enabled` says which types a tour may be created with.
*/
export class TourTypesRepository extends TrekRepository<TourTypes> {}
export class TourTypesRepository extends TrekRepository<TourTypes> {
/** Whether `key` is a known tour type a tour may be created with. */
async isEnabled(key: string): Promise<boolean> {
const row = await this.findOne({ key }, { fields: ['enabled'] });
return row?.enabled === 1;
}
}
@@ -19,7 +19,6 @@ export interface TourListRow {
difficulty: string | null;
wanderer_ref: string | null;
match_confidence: number | null;
tour_group_id: number | null;
max_hiking_difficulty: number;
planned: number;
has_waypoints: number;
@@ -36,7 +35,6 @@ export interface TourRow {
difficulty: string | null;
wanderer_ref: string | null;
match_confidence: number | null;
tour_group_id: number | null;
created_at: string | null;
max_hiking_difficulty: number;
}
@@ -95,7 +93,6 @@ export class ToursRepository extends TrekRepository<Tours> {
't.difficulty as difficulty',
't.wanderer_ref as wanderer_ref',
't.match_confidence as match_confidence',
't.tour_group_id as tour_group_id',
't.max_hiking_difficulty as max_hiking_difficulty',
eb.exists(eb.selectFrom('day_assignments as da').select('da.id').whereRef('da.place_id', '=', 'p.id')).as('planned'),
eb.exists(eb.selectFrom('tour_waypoints as tw').select('tw.id').whereRef('tw.place_id', '=', 'p.id')).as('has_waypoints'),