From 8b2d6840a861d44132740fa65128d45400ebd449 Mon Sep 17 00:00:00 2001 From: Nicolai Ort Date: Tue, 1 Dec 2020 18:57:44 +0100 Subject: [PATCH] Added the track scan class ref #11 --- src/models/TrackScan.ts | 83 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 83 insertions(+) create mode 100644 src/models/TrackScan.ts diff --git a/src/models/TrackScan.ts b/src/models/TrackScan.ts new file mode 100644 index 0000000..c7bc0b9 --- /dev/null +++ b/src/models/TrackScan.ts @@ -0,0 +1,83 @@ +import { PrimaryGeneratedColumn, Column } from "typeorm"; +import { + IsBoolean, + IsDateString, + IsInt, + IsNotEmpty, + IsOptional, + IsPositive, +} from "class-validator"; +import { Scan } from "./Scan"; +import { Runner } from "./Runner"; +import { Track } from "./Track"; +import { RunnerCard } from "./RunnerCard"; +import { ScanStation } from "./ScanStation"; + +/** + * Defines the scan interface. +*/ +export class TrackScan extends Scan { + /** + * Autogenerated unique id (primary key). + */ + @PrimaryGeneratedColumn() + @IsOptional() + @IsInt() + id: number; + + /** + * The associated runner. + */ + @Column() + @IsNotEmpty() + //TODO: Relationship + runner: Runner; + + /** + * The associated track. + */ + @Column() + @IsNotEmpty() + //TODO: Relationship + track: Track; + + /** + * The associated card. + */ + @Column() + @IsNotEmpty() + //TODO: Relationship + card: RunnerCard; + + /** + * The scanning station. + */ + @Column() + @IsNotEmpty() + //TODO: Relationship + station: ScanStation; + + /** + * The scan's distance in meters. + */ + @IsInt() + @IsPositive() + public get distance(): number { + return this.track.distance; + } + + /** + * The scan's creation timestamp. + */ + @Column() + @IsDateString() + @IsNotEmpty() + timestamp: string; + + /** + * Is the scan valid (for fraud reasons). + */ + @Column() + @IsBoolean() + valid = true; +}