backend/src/models/entities/TrackScan.ts

69 lines
1.6 KiB
TypeScript

import {
IsInt,
IsNotEmpty,
IsPositive
} from "class-validator";
import { ChildEntity, Column, ManyToOne } from "typeorm";
import { ResponseTrackScan } from '../responses/ResponseTrackScan';
import { RunnerCard } from "./RunnerCard";
import { Scan } from "./Scan";
import { ScanStation } from "./ScanStation";
import { Track } from "./Track";
/**
* Defines the TrackScan entity.
* A track scan usaually get's generated by a scan station.
*/
@ChildEntity()
export class TrackScan extends Scan {
/**
* The scan's associated track.
* This is used to determine the scan's distance.
*/
@IsNotEmpty()
@ManyToOne(() => Track, track => track.scans, { nullable: true })
track: Track;
/**
* The runnerCard associated with the scan.
* This get's saved for documentation and management purposes.
*/
@IsNotEmpty()
@ManyToOne(() => RunnerCard, card => card.scans, { nullable: true })
card: RunnerCard;
/**
* The scanning station that created the scan.
* Mainly used for logging and traceing back scans (or errors)
*/
@IsNotEmpty()
@ManyToOne(() => ScanStation, station => station.scans, { nullable: true })
station: ScanStation;
/**
* The scan's distance in meters.
* This just get's loaded from it's track.
*/
@IsInt()
@IsPositive()
public get distance(): number {
return this.track.distance;
}
/**
* The scan's creation timestamp.
* Will be used to implement fraud detection.
*/
@Column()
@IsInt()
timestamp: number;
/**
* Turns this entity into it's response class.
*/
public toResponse(): ResponseTrackScan {
return new ResponseTrackScan(this);
}
}