Implemented more stats endpoints

ref #56
This commit is contained in:
2020-12-29 22:17:29 +01:00
parent 555e37eaf7
commit 6e121a3ce2
3 changed files with 32 additions and 5 deletions

View File

@@ -44,4 +44,20 @@ export abstract class RunnerGroup {
*/
@OneToMany(() => Runner, runner => runner.group, { nullable: true })
runners: Runner[];
/**
* Returns the total distance ran by this group's runners based on all their valid scans.
*/
@IsInt()
public get distance(): number {
return this.runners.reduce((sum, current) => sum + current.distance, 0);
}
/**
* Returns the total donations a runner has collected based on his linked donations and distance ran.
*/
@IsInt()
public get distanceDonationAmount(): number {
return this.runners.reduce((sum, current) => sum + current.distanceDonationAmount, 0);
}
}