Merge branch 'dev' of https://git.odit.services/lfk/backend into dev
This commit is contained in:
@@ -28,18 +28,10 @@ export class DistanceDonation extends Donation {
|
||||
* The donation's amount in cents (or whatever your currency's smallest unit is.).
|
||||
* The exact implementation may differ for each type of donation.
|
||||
*/
|
||||
@IsInt()
|
||||
public get amount() {
|
||||
return this.getAmount();
|
||||
}
|
||||
|
||||
/**
|
||||
* The function that calculates the amount based on the runner object's distance.
|
||||
*/
|
||||
public async getAmount(): Promise<number> {
|
||||
public get amount(): number {
|
||||
let calculatedAmount = -1;
|
||||
try {
|
||||
calculatedAmount = this.amountPerDistance * await this.runner.distance();
|
||||
calculatedAmount = this.amountPerDistance * this.runner.distance;
|
||||
} catch (error) {
|
||||
throw error;
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -42,6 +42,4 @@ export abstract class RunnerGroup {
|
||||
*/
|
||||
@OneToMany(() => Runner, runner => runner.group, { nullable: true })
|
||||
runners: Runner[];
|
||||
|
||||
public abstract getRunners();
|
||||
}
|
||||
@@ -1,7 +1,6 @@
|
||||
import { IsOptional } from "class-validator";
|
||||
import { ChildEntity, getConnectionManager, ManyToOne, OneToMany } from "typeorm";
|
||||
import { ChildEntity, ManyToOne, OneToMany } from "typeorm";
|
||||
import { Address } from "./Address";
|
||||
import { Runner } from './Runner';
|
||||
import { RunnerGroup } from "./RunnerGroup";
|
||||
import { RunnerTeam } from "./RunnerTeam";
|
||||
|
||||
@@ -24,27 +23,4 @@ export class RunnerOrganisation extends RunnerGroup {
|
||||
*/
|
||||
@OneToMany(() => RunnerTeam, team => team.parentGroup, { nullable: true })
|
||||
teams: RunnerTeam[];
|
||||
|
||||
|
||||
/**
|
||||
* Returns all runners associated with this organisation or it's teams.
|
||||
*/
|
||||
public async getRunners() {
|
||||
let runners: Runner[] = new Array<Runner>();
|
||||
const teams = await this.getTeams();
|
||||
|
||||
await teams.forEach(async team => {
|
||||
runners.push(... await team.getRunners());
|
||||
});
|
||||
await runners.push(... await getConnectionManager().get().getRepository(Runner).find({ group: this }));
|
||||
|
||||
return runners;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns all teams associated with this organisation.
|
||||
*/
|
||||
public async getTeams() {
|
||||
return await getConnectionManager().get().getRepository(RunnerTeam).find({ parentGroup: this });
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,5 @@
|
||||
import { IsNotEmpty } from "class-validator";
|
||||
import { ChildEntity, getConnectionManager, ManyToOne } from "typeorm";
|
||||
import { Runner } from './Runner';
|
||||
import { ChildEntity, ManyToOne } from "typeorm";
|
||||
import { RunnerGroup } from "./RunnerGroup";
|
||||
import { RunnerOrganisation } from "./RunnerOrganisation";
|
||||
|
||||
@@ -15,13 +14,6 @@ export class RunnerTeam extends RunnerGroup {
|
||||
* Optional
|
||||
*/
|
||||
@IsNotEmpty()
|
||||
@ManyToOne(() => RunnerOrganisation, org => org.teams, { nullable: false })
|
||||
@ManyToOne(() => RunnerOrganisation, org => org.teams, { nullable: true })
|
||||
parentGroup?: RunnerOrganisation;
|
||||
|
||||
/**
|
||||
* Returns all runners associated with this team.
|
||||
*/
|
||||
public async getRunners() {
|
||||
return await getConnectionManager().get().getRepository(Runner).find({ group: this });
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user