Merge branch 'dev' into feature/79-profile_pics
Some checks failed
continuous-integration/drone/pr Build is failing
Some checks failed
continuous-integration/drone/pr Build is failing
This commit is contained in:
@@ -29,7 +29,8 @@ export class ResponseRunner extends ResponseParticipant {
|
||||
*/
|
||||
public constructor(runner: Runner) {
|
||||
super(runner);
|
||||
this.distance = runner.scans.filter(scan => { scan.valid === true }).reduce((sum, current) => sum + current.distance, 0);
|
||||
if (!runner.scans) { this.distance = 0 }
|
||||
else { this.distance = runner.validScans.reduce((sum, current) => sum + current.distance, 0); }
|
||||
this.group = runner.group;
|
||||
}
|
||||
}
|
||||
|
||||
46
src/models/responses/ResponseScan.ts
Normal file
46
src/models/responses/ResponseScan.ts
Normal file
@@ -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 = scan.runner.toResponse();
|
||||
this.distance = scan.distance;
|
||||
this.valid = scan.valid;
|
||||
}
|
||||
}
|
||||
70
src/models/responses/ResponseScanStation.ts
Normal file
70
src/models/responses/ResponseScanStation.ts
Normal file
@@ -0,0 +1,70 @@
|
||||
import {
|
||||
|
||||
IsBoolean,
|
||||
IsInt,
|
||||
|
||||
IsNotEmpty,
|
||||
|
||||
IsObject,
|
||||
|
||||
IsOptional,
|
||||
IsString
|
||||
} from "class-validator";
|
||||
import { ScanStation } from '../entities/ScanStation';
|
||||
import { ResponseTrack } from './ResponseTrack';
|
||||
|
||||
/**
|
||||
* Defines the statsClient response.
|
||||
*/
|
||||
export class ResponseScanStation {
|
||||
/**
|
||||
* The client's id.
|
||||
*/
|
||||
@IsInt()
|
||||
id: number;
|
||||
|
||||
/**
|
||||
* The client's description.
|
||||
*/
|
||||
@IsString()
|
||||
@IsOptional()
|
||||
description?: string;
|
||||
|
||||
/**
|
||||
* The client's api key.
|
||||
* Only visible on creation or regeneration.
|
||||
*/
|
||||
@IsString()
|
||||
@IsOptional()
|
||||
key: string;
|
||||
|
||||
/**
|
||||
* The client's api key prefix.
|
||||
*/
|
||||
@IsString()
|
||||
@IsNotEmpty()
|
||||
prefix: string;
|
||||
|
||||
@IsObject()
|
||||
@IsNotEmpty()
|
||||
track: ResponseTrack;
|
||||
|
||||
/**
|
||||
* Is this station enabled?
|
||||
*/
|
||||
@IsBoolean()
|
||||
enabled?: boolean = true;
|
||||
|
||||
/**
|
||||
* Creates a ResponseStatsClient object from a statsClient.
|
||||
* @param client The statsClient the response shall be build for.
|
||||
*/
|
||||
public constructor(station: ScanStation) {
|
||||
this.id = station.id;
|
||||
this.description = station.description;
|
||||
this.prefix = station.prefix;
|
||||
this.key = "Only visible on creation.";
|
||||
this.track = station.track;
|
||||
this.enabled = station.enabled;
|
||||
}
|
||||
}
|
||||
48
src/models/responses/ResponseTrackScan.ts
Normal file
48
src/models/responses/ResponseTrackScan.ts
Normal file
@@ -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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user