@@ -1,5 +1,5 @@
|
||||
import { IsInt, IsNotEmpty } from "class-validator";
|
||||
import { ChildEntity, getConnectionManager, ManyToOne, OneToMany } from "typeorm";
|
||||
import { ChildEntity, ManyToOne, OneToMany } from "typeorm";
|
||||
import { DistanceDonation } from "./DistanceDonation";
|
||||
import { Participant } from "./Participant";
|
||||
import { RunnerCard } from "./RunnerCard";
|
||||
@@ -36,25 +36,18 @@ export class Runner extends Participant {
|
||||
@OneToMany(() => Scan, scan => scan.runner, { nullable: true })
|
||||
scans: Scan[];
|
||||
|
||||
/**
|
||||
* Returns all scans associated with this runner.
|
||||
*/
|
||||
public async getScans(): Promise<Scan[]> {
|
||||
return await getConnectionManager().get().getRepository(Scan).find({ runner: this });
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns all valid scans associated with this runner.
|
||||
*/
|
||||
public async getValidScans(): Promise<Scan[]> {
|
||||
return (await this.getScans()).filter(scan => { scan.valid === true });
|
||||
public get validScans(): Scan[] {
|
||||
return this.scans.filter(scan => { scan.valid === true });
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the total distance ran by this runner.
|
||||
*/
|
||||
@IsInt()
|
||||
public async distance(): Promise<number> {
|
||||
return await (await this.getValidScans()).reduce((sum, current) => sum + current.distance, 0);
|
||||
public get distance(): number {
|
||||
return this.validScans.reduce((sum, current) => sum + current.distance, 0);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user