Added selfservice scan response class

ref #151
This commit is contained in:
Nicolai Ort 2021-03-01 16:47:54 +01:00
parent 030b2255d4
commit 6074ac5b3a
1 changed files with 57 additions and 0 deletions

View File

@ -0,0 +1,57 @@
import { IsBoolean, IsInt, IsNotEmpty, IsPositive } from "class-validator";
import { Scan } from '../entities/Scan';
import { TrackScan } from '../entities/TrackScan';
import { ResponseObjectType } from '../enums/ResponseObjectType';
import { IResponse } from './IResponse';
/**
* Defines the scan selfservice response.
*/
export class ResponseSelfServiceScan implements IResponse {
/**
* The responseType.
* This contains the type of class/entity this response contains.
*/
responseType: ResponseObjectType = ResponseObjectType.SELFSERVICESCAN;
/**
* The scans's id (for sorting).
*/
@IsInt()
id: number;
/**
* 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;
/**
* The scans's lap time (0 if non is availdable).
*/
@IsInt()
@IsNotEmpty()
lapTime: number = 0;
/**
* Creates a ResponseScan object from a scan.
* @param scan The scan the response shall be build for.
*/
public constructor(scan: Scan | TrackScan) {
this.id = scan.id;
this.distance = scan.distance;
this.valid = scan.valid;
if (scan instanceof TrackScan) {
this.lapTime = scan.lapTime;
this.responseType = ResponseObjectType.SELFSERVICETRACKSCAN;
}
}
}