import { IsInt, IsNotEmpty, IsPositive, IsString } from "class-validator"; import { Column, Entity, OneToMany, PrimaryGeneratedColumn } from "typeorm"; import { ScanStation } from "./ScanStation"; import { TrackScan } from "./TrackScan"; /** * Defines the Track entity. */ @Entity() export class Track { /** * Autogenerated unique id (primary key). */ @PrimaryGeneratedColumn() @IsInt() id: number;; /** * The track's name. * Mainly here for UX. */ @Column() @IsString() @IsNotEmpty() name: string; /** * The track's length/distance in meters. * Will be used to calculate runner's ran distances. */ @Column() @IsInt() @IsPositive() distance: number; /** * Used to link scan stations to a certain track. * This makes the configuration of the scan stations easier. */ @OneToMany(() => ScanStation, station => station.track, { nullable: true }) stations: ScanStation[]; /** * Used to link track scans to a track. * The scan will derive it's distance from the track's distance. */ @OneToMany(() => TrackScan, scan => scan.track, { nullable: true }) scans: TrackScan[]; }