mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-30 00:20:07 +00:00
d5d2d6b25e
A tour can be a city walk. Its points are stations that keep a key across saves, a name, a stay (0 for a point passed through, empty when unknown), an importance and a protection; the visits of a walk's stations are kept per day assignment, so another day or a copy starts with nothing visited. A station that is gone takes its visits with it. An assistant reads how far a walk got on a day, what is open and which times are known.
35 lines
1.3 KiB
TypeScript
35 lines
1.3 KiB
TypeScript
import { EntityRepositoryType, type Opt, PrimaryKeyProp, type Ref, defineEntity, p } from '@mikro-orm/core';
|
|
import { TourStationVisitsRepository } from '../repositories/TourStationVisits.repository';
|
|
import { DbTimestampType } from '../types';
|
|
import { DayAssignments } from './DayAssignments.entity';
|
|
|
|
export class TourStationVisits {
|
|
[EntityRepositoryType]?: TourStationVisitsRepository;
|
|
[PrimaryKeyProp]?: ['assignment', 'station_key'];
|
|
assignment!: Ref<DayAssignments>;
|
|
assignment_id!: number;
|
|
station_key!: string;
|
|
status!: TTourStationVisitsStatus;
|
|
updated_at!: string & Opt;
|
|
}
|
|
|
|
export const TourStationVisitsStatus = {
|
|
VISITED: 'visited',
|
|
SKIPPED: 'skipped',
|
|
} as const;
|
|
|
|
export type TTourStationVisitsStatus = (typeof TourStationVisitsStatus)[keyof typeof TourStationVisitsStatus];
|
|
|
|
export const TourStationVisitsSchema = defineEntity({
|
|
class: TourStationVisits,
|
|
repository: () => TourStationVisitsRepository,
|
|
uniques: [{ properties: ['assignment', 'station_key'] }],
|
|
properties: {
|
|
assignment: () => p.manyToOne(DayAssignments).primary().ref().deleteRule('cascade').hidden(),
|
|
assignment_id: p.integer().persist(false),
|
|
station_key: p.text().primary(),
|
|
status: p.enum(() => TourStationVisitsStatus),
|
|
updated_at: p.type(DbTimestampType).defaultRaw(`CURRENT_TIMESTAMP`),
|
|
},
|
|
});
|