backend/src/models/responses/ResponseTrackScan.ts

66 lines
1.8 KiB
TypeScript

import { IsDateString, IsNotEmpty, IsNumber } from "class-validator";
import { TrackScan } from '../entities/TrackScan';
import { ResponseObjectType } from '../enums/ResponseObjectType';
import { IResponse } from './IResponse';
import { ResponseRunnerCard } from './ResponseRunnerCard';
import { ResponseScan } from './ResponseScan';
import { ResponseScanStation } from './ResponseScanStation';
import { ResponseTrack } from './ResponseTrack';
/**
* Defines the trackScan response.
*/
export class ResponseTrackScan extends ResponseScan implements IResponse {
/**
* The responseType.
* This contains the type of class/entity this response contains.
*/
responseType: ResponseObjectType = ResponseObjectType.TRACKSCAN;
/**
* The scan's associated track.
*/
@IsNotEmpty()
track: ResponseTrack;
/**
* The runnerCard associated with the scan.
*/
@IsNotEmpty()
card: ResponseRunnerCard;
/**
* The scanning station that created the scan.
*/
@IsNotEmpty()
station: ResponseScanStation;
/**
* The scan's creation timestamp.
*/
@IsDateString()
@IsNotEmpty()
timestamp: number;
/**
* The scan's lap time.
* This simply get's calculated from the last lap time;
*/
@IsNumber()
lapTime: number;
/**
* 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);
if (scan.card) { scan.card.toResponse(); }
if (scan.station) { scan.station.toResponse(); }
this.timestamp = scan.timestamp;
this.distance = scan.distance;
this.lapTime = scan.lapTime;
}
}