49 lines
1.1 KiB
TypeScript
49 lines
1.1 KiB
TypeScript
import { IsInt, IsOptional, IsString } from "class-validator";
|
|
import { TrackLapTimeCantBeNegativeError } from '../../errors/TrackErrors';
|
|
import { Track } from '../entities/Track';
|
|
|
|
/**
|
|
* Defines the track response.
|
|
*/
|
|
export class ResponseTrack {
|
|
/**
|
|
* The track's id.
|
|
*/
|
|
@IsInt()
|
|
id: number;;
|
|
|
|
/**
|
|
* The track's name.
|
|
*/
|
|
@IsString()
|
|
name: string;
|
|
|
|
/**
|
|
* The track's length/distance in meters.
|
|
*/
|
|
@IsInt()
|
|
distance: number;
|
|
|
|
/**
|
|
* The minimum time a runner should take to run a lap on this track.
|
|
* Will be used for fraud detection.
|
|
*/
|
|
@IsInt()
|
|
@IsOptional()
|
|
minimumLapTime?: number;
|
|
|
|
/**
|
|
* Creates a ResponseTrack object from a track.
|
|
* @param track The track the response shall be build for.
|
|
*/
|
|
public constructor(track: Track) {
|
|
this.id = track.id;
|
|
this.name = track.name;
|
|
this.distance = track.distance;
|
|
this.minimumLapTime = track.minimumLapTime;
|
|
if (this.minimumLapTime < 0) {
|
|
throw new TrackLapTimeCantBeNegativeError();
|
|
}
|
|
}
|
|
}
|