68 lines
1.4 KiB
TypeScript
68 lines
1.4 KiB
TypeScript
import {
|
|
IsInt,
|
|
IsObject,
|
|
IsString
|
|
} from "class-validator";
|
|
import { Runner } from '../entities/Runner';
|
|
import { RunnerGroup } from '../entities/RunnerGroup';
|
|
|
|
/**
|
|
* Defines the runner response.
|
|
*/
|
|
export class ResponseStatsRunner {
|
|
/**
|
|
* The participant's id.
|
|
*/
|
|
@IsInt()
|
|
id: number;
|
|
|
|
/**
|
|
* The participant's first name.
|
|
*/
|
|
@IsString()
|
|
firstname: string;
|
|
|
|
/**
|
|
* The participant's middle name.
|
|
*/
|
|
@IsString()
|
|
middlename?: string;
|
|
|
|
/**
|
|
* The participant's last name.
|
|
*/
|
|
@IsString()
|
|
lastname: string;
|
|
|
|
/**
|
|
* The runner's currently ran distance in meters.
|
|
*/
|
|
@IsInt()
|
|
distance: number;
|
|
|
|
/**
|
|
* The runner's currently collected donations.
|
|
*/
|
|
@IsInt()
|
|
donationAmount: number;
|
|
|
|
/**
|
|
* The runner's group.
|
|
*/
|
|
@IsObject()
|
|
group: RunnerGroup;
|
|
|
|
/**
|
|
* Creates a ResponseRunner object from a runner.
|
|
* @param runner The user the response shall be build for.
|
|
*/
|
|
public constructor(runner: Runner) {
|
|
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.donationAmount = runner.distanceDonationAmount;
|
|
this.group = runner.group;
|
|
}
|
|
}
|