Files
TREK/server/src/db/entities/TourStationVisits.entity.ts
T
Maurice d5d2d6b25e feat(tours): city walks in the contract and on the server (CW-01, CW-02, CW-03, CW-09, CW-10)
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.
2026-10-20 07:09:56 +00:00

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`),
},
});