Added a response class for team stats

ref #56
This commit is contained in:
2020-12-30 14:41:07 +01:00
parent 35dbfeb5e7
commit ec64ec3d63
3 changed files with 76 additions and 8 deletions

View File

@@ -7,29 +7,30 @@ import { Runner } from '../entities/Runner';
import { RunnerGroup } from '../entities/RunnerGroup';
/**
* Defines the runner response.
* Defines the runner stats response.
* This differs from the normal runner responce.
*/
export class ResponseStatsRunner {
/**
* The participant's id.
* The runner's id.
*/
@IsInt()
id: number;
/**
* The participant's first name.
* The runner's first name.
*/
@IsString()
firstname: string;
/**
* The participant's middle name.
* The runner's middle name.
*/
@IsString()
middlename?: string;
/**
* The participant's last name.
* The runner's last name.
*/
@IsString()
lastname: string;
@@ -57,10 +58,11 @@ export class ResponseStatsRunner {
* @param runner The user the response shall be build for.
*/
public constructor(runner: Runner) {
this.id = runner.id;
this.firstname = runner.firstname;
this.middlename = runner.middlename;
this.lastname = runner.lastname;
this.distance = runner.scans.filter(scan => { scan.valid === true }).reduce((sum, current) => sum + current.distance, 0);
this.distance = runner.distance;
this.donationAmount = runner.distanceDonationAmount;
this.group = runner.group;
}