latest work #20

Merged
philipp merged 233 commits from dev into main 2020-12-09 18:49:33 +00:00
2 changed files with 23 additions and 11 deletions
Showing only changes of commit c30922e325 - Show all commits

View File

@ -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 { Runner } from "./Runner";

View File

@ -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);
}
}