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; +}