73 lines
1.6 KiB
TypeScript
73 lines
1.6 KiB
TypeScript
import {
|
|
IsInt,
|
|
IsNotEmpty,
|
|
IsOptional,
|
|
IsPositive,
|
|
IsString
|
|
} from "class-validator";
|
|
import { Column, Entity, OneToMany, PrimaryGeneratedColumn } from "typeorm";
|
|
import { ResponseTrack } from '../responses/ResponseTrack';
|
|
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;
|
|
|
|
/**
|
|
* The minimum time a runner should take to run a lap on this track (in seconds).
|
|
* Will be used for fraud detection.
|
|
*/
|
|
@Column({ nullable: true })
|
|
@IsInt()
|
|
@IsOptional()
|
|
minimumLapTime?: 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[];
|
|
|
|
/**
|
|
* Turns this entity into it's response class.
|
|
*/
|
|
public toResponse(): ResponseTrack {
|
|
return new ResponseTrack(this);
|
|
}
|
|
}
|