49 lines
1.1 KiB
TypeScript

import {
IsBoolean,
IsInt,
IsNotEmpty,
IsPositive
} from "class-validator";
import { Column, Entity, ManyToOne, PrimaryGeneratedColumn, TableInheritance } from "typeorm";
import { Runner } from "./Runner";
/**
* Defines the Scan entity.
* A scan basicly adds a certain distance to a runner's total ran distance.
*/
@Entity()
@TableInheritance({ column: { name: "type", type: "varchar" } })
export abstract class Scan {
/**
* Autogenerated unique id (primary key).
*/
@PrimaryGeneratedColumn()
@IsInt()
id: number;
/**
* The scan's associated runner.
* This is important to link ran distances to runners.
*/
@IsNotEmpty()
@ManyToOne(() => Runner, runner => runner.scans, { nullable: false })
runner: Runner;
/**
* The scan's distance in meters.
* Can be set manually or derived from another object.
*/
@IsInt()
@IsPositive()
abstract distance: number;
/**
* Is the scan valid (for fraud reasons).
* The determination of validity will work differently for every child class.
* Default: true
*/
@Column()
@IsBoolean()
valid: boolean = true;
}