parent
8beb658bcc
commit
c30922e325
@ -1,5 +1,5 @@
|
|||||||
import { Entity, Column, ManyToOne, ChildEntity } from "typeorm";
|
import { IsInt, IsNotEmpty, IsPositive } from "class-validator";
|
||||||
import { IsInt, IsNotEmpty, IsPositive, } from "class-validator";
|
import { ChildEntity, Column, ManyToOne } from "typeorm";
|
||||||
import { Donation } from "./Donation";
|
import { Donation } from "./Donation";
|
||||||
import { Runner } from "./Runner";
|
import { Runner } from "./Runner";
|
||||||
|
|
||||||
|
@ -36,13 +36,25 @@ export class Runner extends Participant {
|
|||||||
@OneToMany(() => Scan, scan => scan.runner, { nullable: true })
|
@OneToMany(() => Scan, scan => scan.runner, { nullable: true })
|
||||||
scans: Scan[];
|
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 });
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the total distance ran by this runner.
|
||||||
|
*/
|
||||||
@IsInt()
|
@IsInt()
|
||||||
public get distance(): number {
|
public async distance(): Promise<number> {
|
||||||
getConnectionManager().get().getRepository(Scan).find({ runner: this })
|
return await (await this.getValidScans()).reduce((sum, current) => sum + current.distance, 0);
|
||||||
.then(myScans => {
|
|
||||||
return myScans.reduce((sum, current) => sum + current.distance, 0);
|
|
||||||
})
|
|
||||||
.catch(err => { throw err })
|
|
||||||
.finally(do => { return -1; });
|
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user