Files
TREK/server/src/db/entities/PlaceActivityLinks.entity.ts
T
Maurice 382ba79584 feat(places): visits read from trips, change history, linked tours and bookings, personal tags
A visit is a place planned on a day of one of the reader's trips; nothing is kept
or confirmed by hand. A place keeps a log of changes to its details, links the
tours and bookings it is about, and carries tags private to the reader, which a
copy into a trip takes along only when picked. Contracts, routes, MCP tools and
migrations for both engines.
2026-11-29 21:16:50 +01:00

60 lines
3.2 KiB
TypeScript

import { EntityRepositoryType, type Opt, type Ref, defineEntity, p } from '@mikro-orm/core';
import { PlaceActivityLinksRepository } from '../repositories/PlaceActivityLinks.repository';
import { DbTimestampType } from '../types';
import { CollectionPlaces } from './CollectionPlaces.entity';
import { CollectionTours } from './CollectionTours.entity';
import { Places } from './Places.entity';
import { Reservations } from './Reservations.entity';
import { Tours } from './Tours.entity';
import { Users } from './Users.entity';
export class PlaceActivityLinks {
[EntityRepositoryType]?: PlaceActivityLinksRepository;
id!: number & Opt;
place?: Ref<Places> | null;
place_id?: number | null;
reservation?: Ref<Reservations> | null;
reservation_id?: number | null;
tourPlace?: Ref<Tours> | null;
tour_place_id?: number | null;
collectionPlace?: Ref<CollectionPlaces> | null;
collection_place_id?: number | null;
collectionTour?: Ref<CollectionTours> | null;
collection_tour_id?: number | null;
linked_by?: number | null;
created_at?: string | null;
linkedByRef?: Ref<Users> | null;
}
export const PlaceActivityLinksSchema = defineEntity({
class: PlaceActivityLinks,
repository: () => PlaceActivityLinksRepository,
uniques: [
{ properties: ['collectionPlace', 'collectionTour'] },
{ properties: ['place', 'tourPlace'] },
{ properties: ['place', 'reservation'] },
],
checks: [
{
name: 'place_activity_links_collection_tour_id_check',
expression: '(place_id IS NOT NULL AND collection_place_id IS NULL AND collection_tour_id IS NULL AND (reservation_id IS NULL) <> (tour_place_id IS NULL)) OR (place_id IS NULL AND reservation_id IS NULL AND tour_place_id IS NULL AND collection_place_id IS NOT NULL AND collection_tour_id IS NOT NULL)',
},
],
properties: {
id: p.integer().primary(),
place: () => p.manyToOne(Places).ref().deleteRule('cascade').nullable().hidden(),
place_id: p.integer().nullable().persist(false),
reservation: () => p.manyToOne(Reservations).ref().deleteRule('cascade').nullable().hidden().index('idx_place_activity_links_reservation_id'),
reservation_id: p.integer().nullable().persist(false).index('idx_place_activity_links_reservation_id'),
tourPlace: () => p.manyToOne(Tours).ref().joinColumn('tour_place_id').deleteRule('cascade').nullable().hidden().index('idx_place_activity_links_tour_place_id'),
tour_place_id: p.integer().nullable().persist(false).index('idx_place_activity_links_tour_place_id'),
collectionPlace: () => p.manyToOne(CollectionPlaces).ref().deleteRule('cascade').nullable().hidden(),
collection_place_id: p.integer().nullable().persist(false),
collectionTour: () => p.manyToOne(CollectionTours).ref().deleteRule('cascade').nullable().hidden().index('idx_place_activity_links_collection_tour_id'),
collection_tour_id: p.integer().nullable().persist(false).index('idx_place_activity_links_collection_tour_id'),
linked_by: p.integer().nullable().persist(false).index('idx_place_activity_links_linked_by'),
created_at: p.type(DbTimestampType).nullable().defaultRaw(`CURRENT_TIMESTAMP`),
linkedByRef: () => p.manyToOne(Users).ref().joinColumn('linked_by').nullable().hidden().index('idx_place_activity_links_linked_by'),
},
});