@@ -36,13 +36,25 @@ export class Runner extends Participant {
|
||||
@OneToMany(() => Scan, scan => scan.runner, { nullable: true })
|
||||
scans: Scan[];
|
||||
|
||||
@IsInt()
|
||||
public get distance(): number {
|
||||
getConnectionManager().get().getRepository(Scan).find({ runner: this })
|
||||
.then(myScans => {
|
||||
return myScans.reduce((sum, current) => sum + current.distance, 0);
|
||||
})
|
||||
.catch(err => { throw err })
|
||||
.finally(do => { return -1; });
|
||||
/**
|
||||
* 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()
|
||||
public async distance(): Promise<number> {
|
||||
return await (await this.getValidScans()).reduce((sum, current) => sum + current.distance, 0);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user