diff --git a/src/models/responses/ResponseScan.ts b/src/models/responses/ResponseScan.ts new file mode 100644 index 0000000..b5883bd --- /dev/null +++ b/src/models/responses/ResponseScan.ts @@ -0,0 +1,46 @@ +import { IsBoolean, IsInt, IsNotEmpty, IsPositive } from "class-validator"; +import { Scan } from '../entities/Scan'; +import { ResponseRunner } from './ResponseRunner'; + +/** + * Defines the scan response. +*/ +export class ResponseScan { + /** + * The scans's id. + */ + @IsInt() + id: number;; + + /** + * The scan's associated runner. + * This is important to link ran distances to runners. + */ + @IsNotEmpty() + runner: ResponseRunner; + + /** + * Is the scan valid (for fraud reasons). + * The determination of validity will work differently for every child class. + */ + @IsBoolean() + valid: boolean = true; + + /** + * The scans's length/distance in meters. + */ + @IsInt() + @IsPositive() + distance: number; + + /** + * Creates a ResponseScan object from a scan. + * @param scan The scan the response shall be build for. + */ + public constructor(scan: Scan) { + this.id = scan.id; + this.runner = new ResponseRunner(scan.runner); + this.distance = scan.distance; + this.valid = scan.valid; + } +} diff --git a/src/models/responses/ResponseTrackScan.ts b/src/models/responses/ResponseTrackScan.ts new file mode 100644 index 0000000..724a8fd --- /dev/null +++ b/src/models/responses/ResponseTrackScan.ts @@ -0,0 +1,48 @@ +import { IsDateString, IsNotEmpty } from "class-validator"; +import { RunnerCard } from '../entities/RunnerCard'; +import { ScanStation } from '../entities/ScanStation'; +import { TrackScan } from '../entities/TrackScan'; +import { ResponseScan } from './ResponseScan'; +import { ResponseTrack } from './ResponseTrack'; + +/** + * Defines the trackScan response. +*/ +export class ResponseTrackScan extends ResponseScan { + /** + * The scan's associated track. + */ + @IsNotEmpty() + track: ResponseTrack; + + /** + * The runnerCard associated with the scan. + */ + @IsNotEmpty() + card: RunnerCard; + + /** + * The scanning station that created the scan. + */ + @IsNotEmpty() + station: ScanStation; + + /** + * The scan's creation timestamp. + */ + @IsDateString() + @IsNotEmpty() + timestamp: string; + + /** + * Creates a ResponseTrackScan object from a scan. + * @param scan The trackSscan the response shall be build for. + */ + public constructor(scan: TrackScan) { + super(scan); + this.track = new ResponseTrack(scan.track); + this.card = scan.card; + this.station = scan.station; + this.timestamp = scan.timestamp; + } +}